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:
parent
77a1e3dedb
commit
ac99007cab
@ -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{
|
||||
|
16
vlib/v/tests/generic_sumtype_insts_test.v
Normal file
16
vlib/v/tests/generic_sumtype_insts_test.v
Normal 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>'
|
||||
}
|
Loading…
Reference in New Issue
Block a user