mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix for_in_mut_val for maps (#8221)
This commit is contained in:
parent
3ecbf78707
commit
f13ba3a9a8
@ -1362,11 +1362,21 @@ fn (mut g Gen) for_in(it ast.ForInStmt) {
|
|||||||
g.write(' = (*(voidptr*)')
|
g.write(' = (*(voidptr*)')
|
||||||
} else {
|
} else {
|
||||||
val_styp := g.typ(it.val_type)
|
val_styp := g.typ(it.val_type)
|
||||||
g.write('\t$val_styp ${c_name(it.val_var)} = (*($val_styp*)')
|
if it.val_type.is_ptr() {
|
||||||
|
g.write('\t$val_styp ${c_name(it.val_var)} = &(*($val_styp)')
|
||||||
|
} else {
|
||||||
|
g.write('\t$val_styp ${c_name(it.val_var)} = (*($val_styp*)')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
g.writeln('DenseArray_value(&$atmp${arw_or_pt}key_values, $idx));')
|
g.writeln('DenseArray_value(&$atmp${arw_or_pt}key_values, $idx));')
|
||||||
}
|
}
|
||||||
|
if it.val_is_mut {
|
||||||
|
g.for_in_mul_val_name = it.val_var
|
||||||
|
}
|
||||||
g.stmts(it.stmts)
|
g.stmts(it.stmts)
|
||||||
|
if it.val_is_mut {
|
||||||
|
g.for_in_mul_val_name = ''
|
||||||
|
}
|
||||||
if it.key_type == table.string_type && !g.is_builtin_mod {
|
if it.key_type == table.string_type && !g.is_builtin_mod {
|
||||||
// g.writeln('string_free(&$key);')
|
// g.writeln('string_free(&$key);')
|
||||||
}
|
}
|
||||||
|
@ -49,3 +49,12 @@ fn test_for_in_mut_val_of_map() {
|
|||||||
println(m)
|
println(m)
|
||||||
assert '$m' == "{'hello': [2, 4, 6]}"
|
assert '$m' == "{'hello': [2, 4, 6]}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn test_for_in_mut_val_of_map_direct() {
|
||||||
|
mut m := {'foo': 1, 'bar': 2}
|
||||||
|
for _, mut j in m {
|
||||||
|
j = 3
|
||||||
|
}
|
||||||
|
println(m)
|
||||||
|
assert '$m' == "{'foo': 3, 'bar': 3}"
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user