checker: fixes resolution sum type with an alias type

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
pull/13974/head
Vincenzo Palazzo 2022-04-08 19:00:45 +02:00
parent e5809363de
commit a31a4e54ec
No known key found for this signature in database
GPG Key ID: 8B6DC2B870B80D5F
2 changed files with 27 additions and 15 deletions

View File

@ -1280,18 +1280,19 @@ 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
}
} }
return true .alias {
} else { return t.sumtype_check_alias_variant(parent, var_sym.info as Alias, is_as)
for v in parent_info.variants { }
if v.idx() == variant.idx() && (!is_as || v.nr_muls() == variant.nr_muls()) { else {
return true for v in parent_info.variants {
if v.idx() == variant.idx() && (!is_as || v.nr_muls() == variant.nr_muls()) {
return true
}
} }
} }
} }
@ -1299,6 +1300,19 @@ 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

View File

@ -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> {}
} }