cgen: fix generics struct_init (#9661)

pull/9670/head
yuyi 2021-04-10 22:33:15 +08:00 committed by GitHub
parent cf64001474
commit 9f093203a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View File

@ -5002,7 +5002,7 @@ fn (mut g Gen) struct_init(struct_init ast.StructInit) {
g.go_back_out(3)
return
}
sym := g.table.get_final_type_symbol(struct_init.typ)
sym := g.table.get_final_type_symbol(g.unwrap_generic(struct_init.typ))
is_amp := g.is_amp
is_multiline := struct_init.fields.len > 5
g.is_amp = false // reset the flag immediately so that other struct inits in this expr are handled correctly

View File

@ -0,0 +1,15 @@
struct Blah {
mut:
arr []string
}
fn test<T>() T {
return T{}
}
fn test_generics_struct_init() {
mut b := test<Blah>()
b.arr << 'item'
println(b.arr)
assert b.arr == ['item']
}