cgen: fix error for 'in array of sumtype' (#14444)

yuyi 2022-05-18 13:51:31 +08:00 committed by Jef Roosens
parent c5d93afdc1
commit b37130e664
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
2 changed files with 9 additions and 1 deletions

View File

@ -382,7 +382,8 @@ fn (mut g Gen) infix_expr_in_op(node ast.InfixExpr) {
if right.unaliased_sym.kind == .array { if right.unaliased_sym.kind == .array {
if left.sym.kind in [.sum_type, .interface_] { if left.sym.kind in [.sum_type, .interface_] {
if node.right is ast.ArrayInit { 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{} mut infix_exprs := []ast.InfixExpr{}
for i in 0 .. node.right.exprs.len { for i in 0 .. node.right.exprs.len {
infix_exprs << ast.InfixExpr{ infix_exprs << ast.InfixExpr{

View File

@ -309,3 +309,10 @@ fn test_in_alias_array() {
assert Str('') in [Str(''), Str('a')] assert Str('') in [Str(''), Str('a')]
assert Struct{} == Struct{} assert Struct{} == Struct{}
} }
type TokenValue = rune | u64
fn test_in_array_of_sumtype() {
val := TokenValue(`+`)
assert val in [TokenValue(`+`), TokenValue(`-`)]
}