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 {
|
if parent_sym.kind == .sum_type {
|
||||||
parent_info := parent_sym.info as SumType
|
parent_info := parent_sym.info as SumType
|
||||||
var_sym := t.sym(variant)
|
var_sym := t.sym(variant)
|
||||||
if var_sym.kind == .aggregate {
|
match var_sym.kind {
|
||||||
var_info := var_sym.info as Aggregate
|
.aggregate {
|
||||||
for var_type in var_info.types {
|
return t.sumtype_check_aggregate_variant(parent, var_sym.info as Aggregate,
|
||||||
if !t.sumtype_has_variant(parent, var_type, is_as) {
|
is_as)
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
.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 {
|
for v in parent_info.variants {
|
||||||
if v.idx() == variant.idx() && (!is_as || v.nr_muls() == variant.nr_muls()) {
|
if v.idx() == variant.idx() && (!is_as || v.nr_muls() == variant.nr_muls()) {
|
||||||
return true
|
return true
|
||||||
|
|
@ -1296,9 +1296,23 @@ pub fn (t &Table) sumtype_has_variant(parent Type, variant Type, is_as bool) boo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return false
|
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 {
|
pub fn (t &Table) is_sumtype_or_in_variant(parent Type, typ Type) bool {
|
||||||
if typ == 0 {
|
if typ == 0 {
|
||||||
return false
|
return false
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
type ParseRes = Result<[]Token, ParseErr>
|
type ParseRes = Result<[]Token, ParseErr>
|
||||||
|
|
||||||
struct ParseErr{
|
struct ParseErr {}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
type Opt<T> = None<T> | Some<T>
|
type Opt<T> = None<T> | Some<T>
|
||||||
|
|
||||||
|
|
@ -26,7 +24,7 @@ fn test_report() {
|
||||||
r := Opt<ParseRes>(None<ParseRes>{})
|
r := Opt<ParseRes>(None<ParseRes>{})
|
||||||
match r {
|
match r {
|
||||||
Some<ParseRes> {
|
Some<ParseRes> {
|
||||||
rx := Result<[]Token, ParseErr>(r)
|
rx := Result<[]Token, ParseErr>(r.value)
|
||||||
}
|
}
|
||||||
None<ParseRes> {}
|
None<ParseRes> {}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue