1
0
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:
Lukas Neubert 2021-03-06 19:39:38 +01:00 committed by GitHub
parent 9917c6494e
commit 7f7f9dca6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 1 deletions

View 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.')
}
}

View File

@ -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 {

View File

@ -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
}
}