mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
array: fix initialization of empty fixed size arrays
This commit is contained in:
parent
2403abe1ee
commit
b1da59845e
@ -59,7 +59,9 @@ fn (p mut Parser) gen_var_decl(name string, is_static bool) string {
|
|||||||
initializer := p.cgen.cur_line.right(pos)
|
initializer := p.cgen.cur_line.right(pos)
|
||||||
if initializer.len > 0 {
|
if initializer.len > 0 {
|
||||||
p.cgen.resetln(' = {' + initializer.all_after('{') )
|
p.cgen.resetln(' = {' + initializer.all_after('{') )
|
||||||
}
|
} else if initializer.len == 0 {
|
||||||
|
p.cgen.resetln(' = { 0 }')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if is_static {
|
if is_static {
|
||||||
|
@ -164,7 +164,6 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
fn test_fixed() {
|
fn test_fixed() {
|
||||||
/*
|
|
||||||
mut nums := [4]int
|
mut nums := [4]int
|
||||||
assert nums[0] == 0
|
assert nums[0] == 0
|
||||||
assert nums[1] == 0
|
assert nums[1] == 0
|
||||||
@ -174,7 +173,6 @@ fn test_fixed() {
|
|||||||
assert nums[1] == 7
|
assert nums[1] == 7
|
||||||
nums2 := [N]int
|
nums2 := [N]int
|
||||||
assert nums2[N - 1] == 0
|
assert nums2[N - 1] == 0
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn modify (numbers mut []int) {
|
fn modify (numbers mut []int) {
|
||||||
@ -286,7 +284,7 @@ fn test_multi() {
|
|||||||
// TODO
|
// TODO
|
||||||
//b := [ [[1,2,3],[4,5,6]], [[1,2]] ]
|
//b := [ [[1,2,3],[4,5,6]], [[1,2]] ]
|
||||||
//assert b[0][0][0] == 1
|
//assert b[0][0][0] == 1
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_in() {
|
fn test_in() {
|
||||||
a := [1,2,3]
|
a := [1,2,3]
|
||||||
@ -295,7 +293,7 @@ fn test_in() {
|
|||||||
assert 3 in a
|
assert 3 in a
|
||||||
assert !(4 in a)
|
assert !(4 in a)
|
||||||
assert !(0 in a)
|
assert !(0 in a)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn callback_1(val int, index int, arr []int) bool {
|
fn callback_1(val int, index int, arr []int) bool {
|
||||||
return val >= 2
|
return val >= 2
|
||||||
|
Loading…
Reference in New Issue
Block a user