Skip to content

Commit

Permalink
cgen: fix codegen for array append on indexexpr (fix #23156) (#23160)
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp authored Dec 14, 2024
1 parent b39cad2 commit 881fabf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
9 changes: 6 additions & 3 deletions vlib/v/gen/c/index.v
Original file line number Diff line number Diff line change
Expand Up @@ -348,13 +348,16 @@ fn (mut g Gen) index_of_fixed_array(node ast.IndexExpr, sym ast.TypeSymbol) {
g.writeln(';')
g.past_tmp_var_done(past)
} else if node.left is ast.IndexExpr && node.left.is_setter {
past := g.past_tmp_var_new()
line := g.go_before_last_stmt().trim_space()
g.empty_line = true
tmp_var := g.new_tmp_var()
styp := g.styp(node.left_type)
g.write('${styp}* ${past.tmp_var} = &')
g.write('${styp}* ${tmp_var} = &')
g.expr(node.left)
g.writeln(';')
g.write(line)
g.write('(*')
g.past_tmp_var_done(past)
g.write(tmp_var)
g.write(')')
} else {
if is_fn_index_call {
Expand Down
7 changes: 7 additions & 0 deletions vlib/v/tests/left_shift_array_fixed_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fn test_main() {
mut space := [2][2][]int{}
space[1][1] << 123
space[0][0] << 321
assert space[1][1] == [123]
assert space[0][0] == [321]
}

0 comments on commit 881fabf

Please sign in to comment.