diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 7c912f03da..bd9af70e7e 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -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 diff --git a/vlib/v/tests/generics_struct_init_test.v b/vlib/v/tests/generics_struct_init_test.v new file mode 100644 index 0000000000..6af61e6c34 --- /dev/null +++ b/vlib/v/tests/generics_struct_init_test.v @@ -0,0 +1,15 @@ +struct Blah { +mut: + arr []string +} + +fn test() T { + return T{} +} + +fn test_generics_struct_init() { + mut b := test() + b.arr << 'item' + println(b.arr) + assert b.arr == ['item'] +}