diff --git a/vlib/v/ast/table.v b/vlib/v/ast/table.v index 1b3be32c70..0cfe633450 100644 --- a/vlib/v/ast/table.v +++ b/vlib/v/ast/table.v @@ -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 // https://github.com/vlang/v/issues/13863 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 return true diff --git a/vlib/v/tests/cmp_between_alias_and_sum_type.vv b/vlib/v/tests/cmp_between_alias_and_sum_type_test.v similarity index 77% rename from vlib/v/tests/cmp_between_alias_and_sum_type.vv rename to vlib/v/tests/cmp_between_alias_and_sum_type_test.v index 9792010bff..f4bfee8163 100644 --- a/vlib/v/tests/cmp_between_alias_and_sum_type.vv +++ b/vlib/v/tests/cmp_between_alias_and_sum_type_test.v @@ -1,10 +1,10 @@ struct Empty {} + type IndexNumber = u32 type NameIndexType = Empty | IndexNumber -fn main() { +fn test_casting_with_sumtype_and_alias() { elem := NameIndexType(Empty{}) if elem is IndexNumber { - } }