cgen: fix `in` empty array
parent
471c931ada
commit
7e0197c1b8
|
@ -1861,13 +1861,15 @@ fn (mut g Gen) infix_expr(node ast.InfixExpr) {
|
||||||
if right_sym.kind == .array {
|
if right_sym.kind == .array {
|
||||||
match node.right {
|
match node.right {
|
||||||
ast.ArrayInit {
|
ast.ArrayInit {
|
||||||
// `a in [1,2,3]` optimization => `a == 1 || a == 2 || a == 3`
|
if it.exprs.len > 0 {
|
||||||
// avoids an allocation
|
// `a in [1,2,3]` optimization => `a == 1 || a == 2 || a == 3`
|
||||||
// g.write('/*in opt*/')
|
// avoids an allocation
|
||||||
g.write('(')
|
// g.write('/*in opt*/')
|
||||||
g.in_optimization(node.left, it)
|
g.write('(')
|
||||||
g.write(')')
|
g.in_optimization(node.left, it)
|
||||||
return
|
g.write(')')
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {}
|
else {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -214,3 +214,7 @@ fn test_optimized_in_expression_with_string() {
|
||||||
a = 'ab' in ['ab', 'bc'] && false
|
a = 'ab' in ['ab', 'bc'] && false
|
||||||
assert a == false
|
assert a == false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn test_in_array_init() {
|
||||||
|
assert 1 !in []int{}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue