Skip to content

Commit 0fd669d

Browse files
authored
cgen: fix shared array indexing (fix #23410) (#23413)
1 parent 3acbd58 commit 0fd669d

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

vlib/v/gen/c/index.v

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,9 @@ fn (mut g Gen) index_of_fixed_array(node ast.IndexExpr, sym ast.TypeSymbol) {
372372
} else {
373373
g.expr(node.left)
374374
}
375+
if node.left_type.has_flag(.shared_f) {
376+
g.write('.val')
377+
}
375378
}
376379
g.write('[')
377380
if g.is_direct_array_access || g.pref.translated || node.index is ast.IntegerLiteral {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
struct Foo {
2+
mut:
3+
bar shared [10]bool
4+
}
5+
6+
fn test_main() {
7+
mut a := Foo{
8+
bar: [10]bool{}
9+
}
10+
lock a.bar {
11+
a.bar[0] = true
12+
a.bar[1] = false
13+
}
14+
rlock a.bar {
15+
assert a.bar[0] == true
16+
assert a.bar[1] == false
17+
}
18+
}

0 commit comments

Comments
 (0)