cgen: fix for in mut val in array.index() (#12410)

pull/12418/head
yuyi 2021-11-08 17:12:10 +08:00 committed by GitHub
parent 1211029926
commit 758c18a906
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View File

@ -762,6 +762,9 @@ fn (mut g Gen) gen_array_index(node ast.CallExpr) {
}
g.expr(node.left)
g.write(', ')
if node.args[0].expr.is_auto_deref_var() {
g.write('*')
}
g.expr(node.args[0].expr)
g.write(')')
}

View File

@ -0,0 +1,12 @@
fn test_for_in_mut_array_index() {
mut arr := [1, 2, 3, 4, 5]
mut rets := []int{}
for mut val in arr {
inx := arr.index(val)
println(inx)
rets << inx
}
assert rets == [0, 1, 2, 3, 4]
}