cgen: fix map_in mut (#5638)

pull/5643/head
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)
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.expr(node.left)
g.write(', ')
if node.right_type.is_ptr() {
g.write('*')
}
g.expr(node.right)
g.write(')')
} else if right_sym.kind == .string {