diff --git a/vlib/compiler/parser.v b/vlib/compiler/parser.v index afd5f1e02b..28d6b73ccf 100644 --- a/vlib/compiler/parser.v +++ b/vlib/compiler/parser.v @@ -2456,7 +2456,7 @@ fn (p mut Parser) indot_expr() string { if p.tok == .key_in { p.fgen(' ') p.check(.key_in) - //if p.pref.is_debug && p.tok == .lsbr { + p.expected_type = typ // this allows `foo in [.val1, .val2, .val3]` if p.tok == .lsbr { // a in [1,2,3] optimization => `a == 1 || a == 2 || a == 3` // avoids an allocation diff --git a/vlib/compiler/tests/enum_test.v b/vlib/compiler/tests/enum_test.v index f5b746baa4..ce2a17a850 100644 --- a/vlib/compiler/tests/enum_test.v +++ b/vlib/compiler/tests/enum_test.v @@ -22,3 +22,9 @@ fn test_enum() { color = .green assert color == Color.green } + +fn test_in() { + color := Color.red + num := 3 + assert color in [.red, .green] +}