mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix array_slice(*a, 0, a.len)
C error, generated for a[..a.len]
, for a mut a []int
(#8168)
This commit is contained in:
parent
334b66b311
commit
28ed4da1ce
@ -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')
|
||||
|
@ -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)
|
||||
}
|
Loading…
Reference in New Issue
Block a user