diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index 300c5c9e6f..d00988e089 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -3940,6 +3940,12 @@ fn (mut g Gen) index_expr(node ast.IndexExpr) { g.write('_ARR_LEN(') g.expr(node.left) g.write(')') + } else if node.left_type.is_ptr() { + g.write('(') + g.write('*') + g.expr(node.left) + g.write(')') + g.write('.len') } else { g.expr(node.left) g.write('.len') diff --git a/vlib/v/tests/array_slice_test.v b/vlib/v/tests/array_slice_test.v index 2cf12c25c1..e7cdb57368 100644 --- a/vlib/v/tests/array_slice_test.v +++ b/vlib/v/tests/array_slice_test.v @@ -37,3 +37,14 @@ fn test_fixed_array_slice() { arr2 := fixed_array2[0..] assert arr2 == [[1, 2], [2, 3], [3, 4],[4, 5]] } + +fn pointer_array_slice(mut a []int) { + assert a[0..] == [1,2,3] + assert a[..a.len] == [1,2,3] + +} + +fn test_pointer_array_slice() { + mut arr := [1,2,3] + pointer_array_slice(mut arr) +} \ No newline at end of file