diff --git a/vlib/v/gen/c/index.v b/vlib/v/gen/c/index.v index 28c6cdacf42bb7..7bf063901f9a70 100644 --- a/vlib/v/gen/c/index.v +++ b/vlib/v/gen/c/index.v @@ -372,6 +372,9 @@ fn (mut g Gen) index_of_fixed_array(node ast.IndexExpr, sym ast.TypeSymbol) { } else { g.expr(node.left) } + if node.left_type.has_flag(.shared_f) { + g.write('.val') + } } g.write('[') if g.is_direct_array_access || g.pref.translated || node.index is ast.IntegerLiteral { diff --git a/vlib/v/tests/concurrency/shared_array_indexing_test.v b/vlib/v/tests/concurrency/shared_array_indexing_test.v new file mode 100644 index 00000000000000..b92e932d2124b5 --- /dev/null +++ b/vlib/v/tests/concurrency/shared_array_indexing_test.v @@ -0,0 +1,18 @@ +struct Foo { +mut: + bar shared [10]bool +} + +fn test_main() { + mut a := Foo{ + bar: [10]bool{} + } + lock a.bar { + a.bar[0] = true + a.bar[1] = false + } + rlock a.bar { + assert a.bar[0] == true + assert a.bar[1] == false + } +}