diff --git a/vlib/v/gen/c/infix.v b/vlib/v/gen/c/infix.v index f3a2227f898229..c1fa6a72a7f51f 100644 --- a/vlib/v/gen/c/infix.v +++ b/vlib/v/gen/c/infix.v @@ -836,11 +836,7 @@ fn (mut g Gen) infix_expr_in_optimization(left ast.Expr, left_type ast.Type, rig fn (mut g Gen) infix_expr_is_op(node ast.InfixExpr) { mut left_sym := g.table.sym(g.unwrap_generic(g.type_resolver.get_type_or_default(node.left, node.left_type))) - is_aggregate := left_sym.kind == .aggregate - if is_aggregate { - parent_left_type := (left_sym.info as ast.Aggregate).sum_type - left_sym = g.table.sym(parent_left_type) - } + is_aggregate := node.left is ast.Ident && g.comptime.get_ct_type_var(node.left) == .aggregate right_sym := g.table.sym(node.right_type) if left_sym.kind == .interface && right_sym.kind == .interface { g.gen_interface_is_op(node) @@ -880,7 +876,7 @@ fn (mut g Gen) infix_expr_is_op(node ast.InfixExpr) { sub_sym := g.table.sym(sub_type) g.write('_${left_sym.cname}_${sub_sym.cname}_index') return - } else if left_sym.kind == .sum_type { + } else if left_sym.kind == .sum_type || is_aggregate { g.write('_typ ${cmp_op} ') } if node.right is ast.None { diff --git a/vlib/v/tests/typeof_aggregate_test.v b/vlib/v/tests/typeof_aggregate_test.v index 839d87428887db..8a21f0f6457b13 100644 --- a/vlib/v/tests/typeof_aggregate_test.v +++ b/vlib/v/tests/typeof_aggregate_test.v @@ -41,6 +41,6 @@ fn test_typeof_aggregate() { assert rets.len == 3 assert rets[0] == 'The type of `a` is `Foo`' - assert rets[1] == 'The type of `a` is `(Bar | Baz | Bazaar)` and its text says bar' - assert rets[2] == 'The type of `a` is `(Bar | Baz | Bazaar)` and its text says baz' + assert rets[1] == 'The type of `a` is `Bar` and its text says bar' + assert rets[2] == 'The type of `a` is `Baz` and its text says baz' }