cgen: fix `in` in mutable arrays (#5647)

pull/5656/head
yuyi 2020-07-04 18:12:44 +08:00 committed by GitHub
parent 56ad6cef54
commit 27149ba8bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 2 deletions

View File

@ -898,3 +898,15 @@ fn test_mut_arr_with_eq_in_fn() {
mut_arr_with_eq_in_fn(mut a) mut_arr_with_eq_in_fn(mut a)
assert a == [0,0,0,0] assert a == [0,0,0,0]
} }
fn array_in_mut(mut a []int) {
if 1 in a {
a[0] = 2
}
}
fn test_array_in_mut() {
mut a := [1,2]
array_in_mut(mut a)
assert a == [2,2]
}

View File

@ -1912,6 +1912,9 @@ fn (mut g Gen) infix_expr(node ast.InfixExpr) {
g.write('_IN($styp, ') g.write('_IN($styp, ')
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 == .map { } else if right_sym.kind == .map {