diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 0fe74f3d7b..5f00e21457 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -6023,6 +6023,7 @@ fn (mut g Gen) struct_init(struct_init ast.StructInit) { default_init := ast.StructInit{ ...struct_init typ: embed + fields: init_fields_to_embed } g.write('.$embed_name = ') g.struct_init(default_init) diff --git a/vlib/v/tests/multiple_embed_struct_with_duplicate_field_init_test.v b/vlib/v/tests/multiple_embed_struct_with_duplicate_field_init_test.v new file mode 100644 index 0000000000..04dc3b600a --- /dev/null +++ b/vlib/v/tests/multiple_embed_struct_with_duplicate_field_init_test.v @@ -0,0 +1,19 @@ +struct Foo { +mut: + x int +} + +struct Bar { + Foo +mut: + x int +} + +fn test_multiple_embed_struct_with_duplicate_field_init() { + mut b := Bar{ + x: 2 + } + println(b) + assert b.x == 2 + assert b.Foo.x == 0 +}