mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix dereferencing a mutable array (#6191)
This commit is contained in:
parent
fcc61a981d
commit
7dde82322a
@ -2766,6 +2766,9 @@ fn (mut g Gen) index_expr(node ast.IndexExpr) {
|
||||
g.expr(node.left)
|
||||
} else if sym.kind == .array {
|
||||
g.write('array_slice(')
|
||||
if node.left_type.is_ptr() {
|
||||
g.write('*')
|
||||
}
|
||||
g.expr(node.left)
|
||||
} else if sym.kind == .array_fixed {
|
||||
// Convert a fixed array to V array when doing `fixed_arr[start..end]`
|
||||
|
8
vlib/v/tests/array_mut_slicing_test.v
Normal file
8
vlib/v/tests/array_mut_slicing_test.v
Normal file
@ -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
Block a user