1
0
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:
Yarila682 2020-08-22 13:48:09 +03:00 committed by GitHub
parent fcc61a981d
commit 7dde82322a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View File

@ -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]`

View 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)
}