1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

table: fix generic sumtype instantiations (#12288)

This commit is contained in:
yuyi 2021-10-25 20:22:41 +08:00 committed by GitHub
parent 77a1e3dedb
commit ac99007cab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 4 deletions

View File

@ -1771,10 +1771,18 @@ pub fn (mut t Table) generic_insts_to_concrete() {
}
}
for i in 0 .. variants.len {
if t_typ := t.resolve_generic_to_concrete(variants[i], generic_names,
info.concrete_types)
{
variants[i] = t_typ
if variants[i].has_flag(.generic) {
sym := t.get_type_symbol(variants[i])
if sym.kind == .struct_ && variants[i].idx() != info.parent_idx {
variants[i] = t.unwrap_generic_type(variants[i], generic_names,
info.concrete_types)
} else {
if t_typ := t.resolve_generic_to_concrete(variants[i],
generic_names, info.concrete_types)
{
variants[i] = t_typ
}
}
}
}
typ.info = SumType{

View File

@ -0,0 +1,16 @@
struct Foo<T> {
x T
}
struct Bar<T> {
x T
}
type MyType<T> = Bar<T> | Foo<T>
fn test_generic_sumtype_insts() {
f := Foo<string>{'hi'}
t := MyType<string>(f)
println(t.type_name())
assert t.type_name() == 'Foo<string>'
}