diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index 331154f3b0..2ebcfa1de0 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -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]` diff --git a/vlib/v/tests/array_mut_slicing_test.v b/vlib/v/tests/array_mut_slicing_test.v new file mode 100644 index 0000000000..6019dcdd16 --- /dev/null +++ b/vlib/v/tests/array_mut_slicing_test.v @@ -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) +}