checker: take into count the recursive sum type with in alias

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
pull/13974/head
Vincenzo Palazzo 2022-04-11 18:13:59 +02:00
parent 68c5699c1f
commit 93856f82c6
No known key found for this signature in database
GPG Key ID: 8B6DC2B870B80D5F
2 changed files with 6 additions and 3 deletions

View File

@ -1320,7 +1320,10 @@ fn (t &Table) sumtype_check_alias_variant(parent_type Type, alias_type Type, is_
// the alias is not inside one of the Sum type, like // the alias is not inside one of the Sum type, like
// https://github.com/vlang/v/issues/13863 // https://github.com/vlang/v/issues/13863
alias_info := t.sym(alias_type).info as Alias alias_info := t.sym(alias_type).info as Alias
return t.sumtype_has_variant(parent_type, alias_info.parent_type, is_as) // The alias is an alias or of the same type of the parent or one
// of the SumType variant. e.g: alias of another sum type
return parent_type == alias_info.parent_type
|| t.sumtype_has_variant(parent_type, alias_info.parent_type, is_as)
} }
// the alias_type is inside one of the variant of the sum type // the alias_type is inside one of the variant of the sum type
return true return true

View File

@ -1,10 +1,10 @@
struct Empty {} struct Empty {}
type IndexNumber = u32 type IndexNumber = u32
type NameIndexType = Empty | IndexNumber type NameIndexType = Empty | IndexNumber
fn main() { fn test_casting_with_sumtype_and_alias() {
elem := NameIndexType(Empty{}) elem := NameIndexType(Empty{})
if elem is IndexNumber { if elem is IndexNumber {
} }
} }