From b37130e6640e9adc75c89c02614a69d66fea18df Mon Sep 17 00:00:00 2001 From: yuyi Date: Wed, 18 May 2022 13:51:31 +0800 Subject: [PATCH] cgen: fix error for 'in array of sumtype' (#14444) --- vlib/v/gen/c/infix.v | 3 ++- vlib/v/tests/in_expression_test.v | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/vlib/v/gen/c/infix.v b/vlib/v/gen/c/infix.v index 65e8b53ee3..81b2ac4b88 100644 --- a/vlib/v/gen/c/infix.v +++ b/vlib/v/gen/c/infix.v @@ -382,7 +382,8 @@ fn (mut g Gen) infix_expr_in_op(node ast.InfixExpr) { if right.unaliased_sym.kind == .array { if left.sym.kind in [.sum_type, .interface_] { if node.right is ast.ArrayInit { - if node.right.exprs.len > 0 { + if node.right.exprs.len > 0 + && g.table.sym(node.right.expr_types[0]).kind !in [.sum_type, .interface_] { mut infix_exprs := []ast.InfixExpr{} for i in 0 .. node.right.exprs.len { infix_exprs << ast.InfixExpr{ diff --git a/vlib/v/tests/in_expression_test.v b/vlib/v/tests/in_expression_test.v index 34a9a5c37f..458fb8bc9a 100644 --- a/vlib/v/tests/in_expression_test.v +++ b/vlib/v/tests/in_expression_test.v @@ -309,3 +309,10 @@ fn test_in_alias_array() { assert Str('') in [Str(''), Str('a')] assert Struct{} == Struct{} } + +type TokenValue = rune | u64 + +fn test_in_array_of_sumtype() { + val := TokenValue(`+`) + assert val in [TokenValue(`+`), TokenValue(`-`)] +}