cgen: fix `in` empty array
parent
471c931ada
commit
7e0197c1b8
|
@ -1861,6 +1861,7 @@ 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 {
|
||||||
|
if it.exprs.len > 0 {
|
||||||
// `a in [1,2,3]` optimization => `a == 1 || a == 2 || a == 3`
|
// `a in [1,2,3]` optimization => `a == 1 || a == 2 || a == 3`
|
||||||
// avoids an allocation
|
// avoids an allocation
|
||||||
// g.write('/*in opt*/')
|
// g.write('/*in opt*/')
|
||||||
|
@ -1869,6 +1870,7 @@ fn (mut g Gen) infix_expr(node ast.InfixExpr) {
|
||||||
g.write(')')
|
g.write(')')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else {}
|
else {}
|
||||||
}
|
}
|
||||||
styp := g.typ(g.table.mktyp(left_type))
|
styp := g.typ(g.table.mktyp(left_type))
|
||||||
|
|
|
@ -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