mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
ast: fix generic nested struct init (#12405)
This commit is contained in:
parent
1c12186701
commit
9ec1262734
@ -1661,16 +1661,14 @@ pub fn (mut t Table) generic_insts_to_concrete() {
|
||||
generic_names := parent_info.generic_types.map(t.get_type_symbol(it).name)
|
||||
for i in 0 .. fields.len {
|
||||
if fields[i].typ.has_flag(.generic) {
|
||||
sym := t.get_type_symbol(fields[i].typ)
|
||||
if sym.kind == .struct_ && fields[i].typ.idx() != info.parent_idx {
|
||||
if fields[i].typ.idx() != info.parent_idx {
|
||||
fields[i].typ = t.unwrap_generic_type(fields[i].typ,
|
||||
generic_names, info.concrete_types)
|
||||
} else {
|
||||
if t_typ := t.resolve_generic_to_concrete(fields[i].typ,
|
||||
generic_names, info.concrete_types)
|
||||
{
|
||||
fields[i].typ = t_typ
|
||||
}
|
||||
}
|
||||
if t_typ := t.resolve_generic_to_concrete(fields[i].typ,
|
||||
generic_names, info.concrete_types)
|
||||
{
|
||||
fields[i].typ = t_typ
|
||||
}
|
||||
}
|
||||
}
|
||||
|
25
vlib/v/tests/generics_nested_struct_init_test.v
Normal file
25
vlib/v/tests/generics_nested_struct_init_test.v
Normal file
@ -0,0 +1,25 @@
|
||||
struct Foo<T> {
|
||||
foo T
|
||||
}
|
||||
|
||||
struct Bar<T> {
|
||||
mut:
|
||||
foos []Foo<T>
|
||||
}
|
||||
|
||||
fn (mut b Bar<T>) add(v T) {
|
||||
b.foos << Foo<T>{
|
||||
foo: v
|
||||
}
|
||||
}
|
||||
|
||||
fn test_nested_generics_struct_init() {
|
||||
mut bar := Bar<string>{}
|
||||
bar.add('bar')
|
||||
println(bar)
|
||||
|
||||
result := '$bar'
|
||||
assert result.contains('Bar<string>{')
|
||||
assert result.contains('foos: [Foo<string>{')
|
||||
assert result.contains("foo: 'bar'")
|
||||
}
|
Loading…
Reference in New Issue
Block a user