cgen: fix shared array indexing (fix #23410) (#23413)

This commit is contained in:
Felipe Pena 2025-01-09 04:02:39 -03:00 committed by GitHub
parent 3acbd580d4
commit 0fd669d203
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 0 deletions

View File

@ -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 {

View File

@ -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
}
}