table: fix generic sumtype instantiations (#12288)
parent
77a1e3dedb
commit
ac99007cab
|
@ -1771,12 +1771,20 @@ pub fn (mut t Table) generic_insts_to_concrete() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for i in 0 .. variants.len {
|
for i in 0 .. variants.len {
|
||||||
if t_typ := t.resolve_generic_to_concrete(variants[i], generic_names,
|
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)
|
info.concrete_types)
|
||||||
|
} else {
|
||||||
|
if t_typ := t.resolve_generic_to_concrete(variants[i],
|
||||||
|
generic_names, info.concrete_types)
|
||||||
{
|
{
|
||||||
variants[i] = t_typ
|
variants[i] = t_typ
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
typ.info = SumType{
|
typ.info = SumType{
|
||||||
...parent_info
|
...parent_info
|
||||||
is_generic: false
|
is_generic: false
|
||||||
|
|
|
@ -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>'
|
||||||
|
}
|
Loading…
Reference in New Issue