diff --git a/vlib/v/gen/c/struct.v b/vlib/v/gen/c/struct.v index babd6cbe3b..6245364544 100644 --- a/vlib/v/gen/c/struct.v +++ b/vlib/v/gen/c/struct.v @@ -195,7 +195,9 @@ fn (mut g Gen) struct_init(node ast.StructInit) { if is_update_tmp_var { g.write(tmp_update_var) } else { + g.write('(') g.expr(node.update_expr) + g.write(')') } if node.update_expr_type.is_ptr() { g.write('->') diff --git a/vlib/v/tests/struct_init_with_update_test.v b/vlib/v/tests/struct_init_with_update_test.v index c2c398e046..cf1a1dd6c8 100644 --- a/vlib/v/tests/struct_init_with_update_test.v +++ b/vlib/v/tests/struct_init_with_update_test.v @@ -30,3 +30,21 @@ fn test_struct_init_with_update_expr() { assert o.height == 175 assert o.age == 21 } + +struct Foo { + s string + n int +} + +fn test_struct_init_with_update_expr2() { + f := &Foo{ + s: 'AA' + } + b := Foo{ + ...*f + n: 3 + } + println(b) + assert b.s == 'AA' + assert b.n == 3 +}