mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix for in mut val in array.index() (#12410)
This commit is contained in:
parent
1211029926
commit
758c18a906
@ -762,6 +762,9 @@ fn (mut g Gen) gen_array_index(node ast.CallExpr) {
|
|||||||
}
|
}
|
||||||
g.expr(node.left)
|
g.expr(node.left)
|
||||||
g.write(', ')
|
g.write(', ')
|
||||||
|
if node.args[0].expr.is_auto_deref_var() {
|
||||||
|
g.write('*')
|
||||||
|
}
|
||||||
g.expr(node.args[0].expr)
|
g.expr(node.args[0].expr)
|
||||||
g.write(')')
|
g.write(')')
|
||||||
}
|
}
|
||||||
|
12
vlib/v/tests/for_in_mut_array_index_test.v
Normal file
12
vlib/v/tests/for_in_mut_array_index_test.v
Normal 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]
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user