parser,fmt: fix regression with non-void arrays in if conditions (#9161)
parent
9917c6494e
commit
7f7f9dca6b
|
@ -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 has_cap := false
|
||||||
mut len_expr := ast.Expr{}
|
mut len_expr := ast.Expr{}
|
||||||
mut cap_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
|
// `[]int{ len: 10, cap: 100}` syntax
|
||||||
p.next()
|
p.next()
|
||||||
for p.tok.kind != .rcbr {
|
for p.tok.kind != .rcbr {
|
||||||
|
|
|
@ -180,3 +180,14 @@ fn test_if_expr_with_array_map() {
|
||||||
println(assigned)
|
println(assigned)
|
||||||
assert assigned == [2, 3]
|
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