1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: fix map_in mut (#5638)

This commit is contained in:
yuyi 2020-07-03 22:33:53 +08:00 committed by GitHub
parent df2749dd50
commit dff385cb37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View File

@ -301,3 +301,15 @@ fn test_map_keys_to_array() {
println(sarr) println(sarr)
assert sarr == "['a', 'c']" assert sarr == "['a', 'c']"
} }
fn map_in_mut(mut m map[string]int) {
if 'one' in m {
m['one'] = 2
}
}
fn test_map_in_mut() {
mut m := {'one': 1}
map_in_mut(mut m)
assert m['one'] == 2
}

View File

@ -1912,6 +1912,9 @@ fn (mut g Gen) infix_expr(node ast.InfixExpr) {
g.write('_IN_MAP(') g.write('_IN_MAP(')
g.expr(node.left) g.expr(node.left)
g.write(', ') g.write(', ')
if node.right_type.is_ptr() {
g.write('*')
}
g.expr(node.right) g.expr(node.right)
g.write(')') g.write(')')
} else if right_sym.kind == .string { } else if right_sym.kind == .string {