Skip to content

Commit

Permalink
cgen: fix generics struct_init (#9661)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyi98 committed Apr 10, 2021
1 parent cf64001 commit 9f09320
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion vlib/v/gen/c/cgen.v
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions vlib/v/tests/generics_struct_init_test.v
@@ -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']
}

0 comments on commit 9f09320

Please sign in to comment.