cgen: fix dereferencing a mutable array (#6191)
parent
fcc61a981d
commit
7dde82322a
|
@ -2766,6 +2766,9 @@ fn (mut g Gen) index_expr(node ast.IndexExpr) {
|
||||||
g.expr(node.left)
|
g.expr(node.left)
|
||||||
} else if sym.kind == .array {
|
} else if sym.kind == .array {
|
||||||
g.write('array_slice(')
|
g.write('array_slice(')
|
||||||
|
if node.left_type.is_ptr() {
|
||||||
|
g.write('*')
|
||||||
|
}
|
||||||
g.expr(node.left)
|
g.expr(node.left)
|
||||||
} else if sym.kind == .array_fixed {
|
} else if sym.kind == .array_fixed {
|
||||||
// Convert a fixed array to V array when doing `fixed_arr[start..end]`
|
// Convert a fixed array to V array when doing `fixed_arr[start..end]`
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
fn array_mut_slice(mut a []int) {
|
||||||
|
assert a[1..3].map(it) == [3, 5]
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_array_mut_slice() {
|
||||||
|
mut a := [1, 3, 5, 7, 9]
|
||||||
|
array_mut_slice(mut a)
|
||||||
|
}
|
Loading…
Reference in New Issue