File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -394,6 +394,22 @@ fn (mut g Gen) infix_expr_in_op(node ast.InfixExpr) {
394394 return
395395 }
396396 }
397+ if right.sym.info is ast.Array {
398+ elem_type := right.sym.info.elem_type
399+ elem_type_ := g.unwrap (elem_type)
400+ if elem_type_.sym.kind == .sum_type {
401+ if node.left_type in elem_type_.sym.sumtype_info ().variants {
402+ new_node_left := ast.CastExpr{
403+ arg: ast.EmptyExpr{}
404+ typ: elem_type
405+ expr: node.left
406+ expr_type: node.left_type
407+ }
408+ g.gen_array_contains (node.right_type, node.right, new_node_left)
409+ return
410+ }
411+ }
412+ }
397413 g.gen_array_contains (node.right_type, node.right, node.left)
398414 } else if right.unaliased_sym.kind == .map {
399415 g.write ('_IN_MAP(' )
Original file line number Diff line number Diff line change @@ -280,4 +280,10 @@ fn test_in_sumtype_array() {
280280 println (foo)
281281 assert true
282282 }
283+
284+ // without sumtype cast
285+ mut foos := []Foo{}
286+ foos << Foo1 {}
287+ assert Foo1 {} in foos
288+ assert Foo2 {} ! in foos
283289}
You can’t perform that action at this time.
0 commit comments