cgen: fix for in mut val in array.index() (#12410)
parent
1211029926
commit
758c18a906
|
@ -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(')')
|
||||
}
|
||||
|
|
|
@ -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]
|
||||
}
|
Loading…
Reference in New Issue