mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser,fmt: fix regression with non-void arrays in if conditions (#9161)
This commit is contained in:
parent
9917c6494e
commit
7f7f9dca6b
11
vlib/v/fmt/tests/if_keep.vv
Normal file
11
vlib/v/fmt/tests/if_keep.vv
Normal file
@ -0,0 +1,11 @@
|
||||
fn void_type_array_cond() {
|
||||
if fg == [] {
|
||||
stack.ctx.reset_color()
|
||||
}
|
||||
}
|
||||
|
||||
fn multi_dimensional_array_cond() {
|
||||
if t.data == [][]string{} {
|
||||
return error('Table.data should not be empty.')
|
||||
}
|
||||
}
|
@ -105,7 +105,7 @@ fn (mut p Parser) array_init() ast.ArrayInit {
|
||||
mut has_cap := false
|
||||
mut len_expr := ast.Expr{}
|
||||
mut cap_expr := ast.Expr{}
|
||||
if p.tok.kind == .lcbr && exprs.len == 0 && !p.inside_if {
|
||||
if p.tok.kind == .lcbr && exprs.len == 0 && array_type != table.void_type {
|
||||
// `[]int{ len: 10, cap: 100}` syntax
|
||||
p.next()
|
||||
for p.tok.kind != .rcbr {
|
||||
|
@ -180,3 +180,14 @@ fn test_if_expr_with_array_map() {
|
||||
println(assigned)
|
||||
assert assigned == [2, 3]
|
||||
}
|
||||
|
||||
fn test_if_epxr_with_array_conditions() {
|
||||
num_arr := [1, 2, 3]
|
||||
if num_arr == [] {
|
||||
assert false
|
||||
}
|
||||
str_arr := [['foo'], ['bar']]
|
||||
if str_arr == [][]string{} {
|
||||
assert false
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user