cgen: fix for_mut_val_in_map_fixed_array (#8314)
parent
ebda57fa6f
commit
d3327ba50f
|
@ -1978,7 +1978,14 @@ fn (mut g Gen) gen_assign_stmt(assign_stmt ast.AssignStmt) {
|
||||||
right := val as ast.ArrayInit
|
right := val as ast.ArrayInit
|
||||||
if right.has_val {
|
if right.has_val {
|
||||||
for j, expr in right.exprs {
|
for j, expr in right.exprs {
|
||||||
|
if !is_decl && left is ast.Ident
|
||||||
|
&& g.for_in_mul_val_name == (left as ast.Ident).name {
|
||||||
|
g.write('(*')
|
||||||
g.expr(left)
|
g.expr(left)
|
||||||
|
g.write(')')
|
||||||
|
} else {
|
||||||
|
g.expr(left)
|
||||||
|
}
|
||||||
if g.is_array_set {
|
if g.is_array_set {
|
||||||
g.out.go_back(2)
|
g.out.go_back(2)
|
||||||
} else {
|
} else {
|
||||||
|
@ -1995,7 +2002,14 @@ fn (mut g Gen) gen_assign_stmt(assign_stmt ast.AssignStmt) {
|
||||||
} else {
|
} else {
|
||||||
fixed_array := right_sym.info as table.ArrayFixed
|
fixed_array := right_sym.info as table.ArrayFixed
|
||||||
for j in 0 .. fixed_array.size {
|
for j in 0 .. fixed_array.size {
|
||||||
|
if !is_decl && left is ast.Ident
|
||||||
|
&& g.for_in_mul_val_name == (left as ast.Ident).name {
|
||||||
|
g.write('(*')
|
||||||
g.expr(left)
|
g.expr(left)
|
||||||
|
g.write(')')
|
||||||
|
} else {
|
||||||
|
g.expr(left)
|
||||||
|
}
|
||||||
if g.is_array_set {
|
if g.is_array_set {
|
||||||
g.out.go_back(2)
|
g.out.go_back(2)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -58,3 +58,12 @@ fn test_for_in_mut_val_of_map_direct() {
|
||||||
println(m)
|
println(m)
|
||||||
assert '$m' == "{'foo': 3, 'bar': 3}"
|
assert '$m' == "{'foo': 3, 'bar': 3}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn test_for_in_mut_val_of_map_fixed_array() {
|
||||||
|
mut m := {'foo': [{'a': 1}]!, 'bar': [{'b': 2}]!}
|
||||||
|
for _, mut j in m {
|
||||||
|
j = [{'c': 3}]!
|
||||||
|
}
|
||||||
|
println(m)
|
||||||
|
assert '$m' == "{'foo': [{'c': 3}], 'bar': [{'c': 3}]}"
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue