cgen: fix if expr with complex nested array call (#11979)

pull/11981/head
yuyi 2021-09-26 12:35:48 +08:00 committed by GitHub
parent da47638f42
commit e09860731f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 0 deletions

View File

@ -160,6 +160,7 @@ fn (mut g Gen) gen_array_map(node ast.CallExpr) {
has_infix_left_var_name := g.infix_left_var_name.len > 0
if has_infix_left_var_name {
g.writeln('if ($g.infix_left_var_name) {')
g.infix_left_var_name = ''
g.indent++
}
g.write('${g.typ(node.left_type)} ${tmp}_orig = ')
@ -352,6 +353,7 @@ fn (mut g Gen) gen_array_filter(node ast.CallExpr) {
has_infix_left_var_name := g.infix_left_var_name.len > 0
if has_infix_left_var_name {
g.writeln('if ($g.infix_left_var_name) {')
g.infix_left_var_name = ''
g.indent++
}
g.write('${g.typ(node.left_type)} ${tmp}_orig = ')
@ -645,6 +647,7 @@ fn (mut g Gen) gen_array_any(node ast.CallExpr) {
has_infix_left_var_name := g.infix_left_var_name.len > 0
if has_infix_left_var_name {
g.writeln('if ($g.infix_left_var_name) {')
g.infix_left_var_name = ''
g.indent++
}
g.write('${g.typ(node.left_type)} ${tmp}_orig = ')
@ -728,6 +731,7 @@ fn (mut g Gen) gen_array_all(node ast.CallExpr) {
has_infix_left_var_name := g.infix_left_var_name.len > 0
if has_infix_left_var_name {
g.writeln('if ($g.infix_left_var_name) {')
g.infix_left_var_name = ''
g.indent++
}
g.write('${g.typ(node.left_type)} ${tmp}_orig = ')

View File

@ -13,3 +13,11 @@ fn test_if_expr_with_nested_array_call2() {
assert true
}
}
fn test_if_expr_with_nested_array_call3() {
arr := ['abc']
if arr.len == 0 || arr.all(it.bytes().map(it).filter(it != ` `).any(it == `c`)) {
println('yes')
assert true
}
}