1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

arrays: use for/in instead of unsafe [direct_array_access] (#8857)

This commit is contained in:
Nick Treleaven
2021-02-20 13:27:36 +00:00
committed by GitHub
parent 38d1eac7f5
commit 2be852e461
3 changed files with 36 additions and 41 deletions

View File

@@ -18,6 +18,27 @@ fn test_fixed_array_can_be_assigned() {
assert v[1] == 3.0
}
fn test_fixed_array_assignment() {
mut a := [2]int{}
a[0] = 111
a[1] = 222
b := a
assert b[0] == a[0]
assert b[1] == a[1]
mut c := [2]int{}
c = a
assert c[0] == a[0]
assert c[1] == a[1]
d := [3]int{init: 333}
for val in d {
assert val == 333
}
e := [3]string{init: 'vlang'}
for val in e {
assert val == 'vlang'
}
}
fn test_fixed_array_can_be_used_in_declaration() {
x := 2.32
v := [1.0, x, 3.0,4.0,5.0,6.0,7.0,8.0]!
@@ -99,3 +120,4 @@ fn test_for_in_fixed_array() {
arr := [1,2,3]!
calc_size(arr)
}