fix fixed_array slice ommit high_value (#8025)

pull/8125/head^2
BigBlack 2021-01-15 17:28:20 +08:00 committed by GitHub
parent 57dd511c9d
commit 80008a40e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 0 deletions

View File

@ -3894,6 +3894,10 @@ fn (mut g Gen) index_expr(node ast.IndexExpr) {
g.write(', ') g.write(', ')
if node.index.has_high { if node.index.has_high {
g.expr(node.index.high) g.expr(node.index.high)
} else if sym.kind == .array_fixed {
g.write('_ARR_LEN(')
g.expr(node.left)
g.write(')')
} else { } else {
g.expr(node.left) g.expr(node.left)
g.write('.len') g.write('.len')

View File

@ -29,3 +29,11 @@ fn test_access_slice_attribute() {
assert access_slice_attribute(mut arr) == 4 assert access_slice_attribute(mut arr) == 4
} }
fn test_fixed_array_slice() {
fixed_array1 := [1, 2, 3]!
arr1 := fixed_array1[0..]
assert arr1 == [1, 2, 3]
fixed_array2 := [[1, 2], [2, 3], [3, 4],[4, 5]]!
arr2 := fixed_array2[0..]
assert arr2 == [[1, 2], [2, 3], [3, 4],[4, 5]]
}