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