checker: fixes resolution sum type with an alias type
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>pull/13974/head
parent
e5809363de
commit
a31a4e54ec
|
|
@ -1280,15 +1280,15 @@ pub fn (t &Table) sumtype_has_variant(parent Type, variant Type, is_as bool) boo
|
|||
if parent_sym.kind == .sum_type {
|
||||
parent_info := parent_sym.info as SumType
|
||||
var_sym := t.sym(variant)
|
||||
if var_sym.kind == .aggregate {
|
||||
var_info := var_sym.info as Aggregate
|
||||
for var_type in var_info.types {
|
||||
if !t.sumtype_has_variant(parent, var_type, is_as) {
|
||||
return false
|
||||
match var_sym.kind {
|
||||
.aggregate {
|
||||
return t.sumtype_check_aggregate_variant(parent, var_sym.info as Aggregate,
|
||||
is_as)
|
||||
}
|
||||
.alias {
|
||||
return t.sumtype_check_alias_variant(parent, var_sym.info as Alias, is_as)
|
||||
}
|
||||
return true
|
||||
} else {
|
||||
else {
|
||||
for v in parent_info.variants {
|
||||
if v.idx() == variant.idx() && (!is_as || v.nr_muls() == variant.nr_muls()) {
|
||||
return true
|
||||
|
|
@ -1296,9 +1296,23 @@ pub fn (t &Table) sumtype_has_variant(parent Type, variant Type, is_as bool) boo
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
fn (t &Table) sumtype_check_aggregate_variant(parent_type Type, aggregate_sym &Aggregate, is_as bool) bool {
|
||||
for var_type in aggregate_sym.types {
|
||||
if !t.sumtype_has_variant(parent_type, var_type, is_as) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
fn (t &Table) sumtype_check_alias_variant(parent_type Type, alias_info &Alias, is_as bool) bool {
|
||||
return alias_info.parent_type == parent_type
|
||||
}
|
||||
|
||||
pub fn (t &Table) is_sumtype_or_in_variant(parent Type, typ Type) bool {
|
||||
if typ == 0 {
|
||||
return false
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
type ParseRes = Result<[]Token, ParseErr>
|
||||
|
||||
struct ParseErr{
|
||||
|
||||
}
|
||||
struct ParseErr {}
|
||||
|
||||
type Opt<T> = None<T> | Some<T>
|
||||
|
||||
|
|
@ -26,7 +24,7 @@ fn test_report() {
|
|||
r := Opt<ParseRes>(None<ParseRes>{})
|
||||
match r {
|
||||
Some<ParseRes> {
|
||||
rx := Result<[]Token, ParseErr>(r)
|
||||
rx := Result<[]Token, ParseErr>(r.value)
|
||||
}
|
||||
None<ParseRes> {}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue