diff --git a/vlib/v/gen/c/struct.v b/vlib/v/gen/c/struct.v index d38a7e9407..e46f149512 100644 --- a/vlib/v/gen/c/struct.v +++ b/vlib/v/gen/c/struct.v @@ -161,9 +161,7 @@ fn (mut g Gen) struct_init(node ast.StructInit) { g.is_shared = old_is_shared2 } for mut field in info.fields { - if !field.typ.has_flag(.shared_f) { - g.is_shared = false - } + g.is_shared = field.typ.has_flag(.shared_f) if mut sym.info is ast.Struct { mut found_equal_fields := 0 for mut sifield in sym.info.fields { @@ -280,7 +278,6 @@ fn (mut g Gen) struct_init(node ast.StructInit) { g.write(',') } initialized = true - g.is_shared = old_is_shared } g.is_shared = old_is_shared } diff --git a/vlib/v/tests/shared_struct_field_test.v b/vlib/v/tests/shared_struct_field_test.v new file mode 100644 index 0000000000..0a68ddba9b --- /dev/null +++ b/vlib/v/tests/shared_struct_field_test.v @@ -0,0 +1,13 @@ +module main + +struct StructA { + ints shared []int = [0] +} + +fn test_main() { + a := StructA{} + rlock a.ints { + dump(a) + assert true + } +}