Skip to content

Commit

Permalink
cgen: fix shared array indexing (fix #23410) (#23413)
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp authored Jan 9, 2025
1 parent 3acbd58 commit 0fd669d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions vlib/v/gen/c/index.v
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 18 additions & 0 deletions vlib/v/tests/concurrency/shared_array_indexing_test.v
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit 0fd669d

Please sign in to comment.