Skip to content

Enum variant referenced with call parens (Color.Red()) passes with check but fails codegen #566

Closed

Description

@ehartford

Found while investigating #563 (test/lexer, test/parser wiring). The old paren-call style for plain enum variants is accepted by sema but dies in codegen.

Repro

// enum_variant_parens.w
enum Color: i32:
    Red = 1
    Blue = 2

fn main:
    assert(Color.Red() == Color.Red)
    print("ok")
$ with check enum_variant_parens.w
ok
$ with build enum_variant_parens.w
error: aggregate rvalue missing destination struct type fn=main count=0 dest_sema=84 current_ret=void
error: code generation failed

Expected vs actual

  • Expected: either the paren form lowers identically to Color.Red (it's a unit variant of an i32-repr enum), or sema rejects it with a real diagnostic.
  • Actual: with check accepts it, codegen fails with an internal aggregate rvalue missing destination struct type error. Sema and codegen disagree about what the expression is.

Same failure with cross-module pub enums, in comparisons (x == Color.Red()), and in argument position. Color.Red (no parens) works everywhere.

Context / workaround

test/lexer/*.w and test/parser/parser_unit_test.w use this paren style pervasively (TokenKind.TK_EOF(), NodeKind.NK_INT_LIT()); the #563 fix will drop the parens in those tests as API drift, so this issue is only about the sema/codegen mismatch itself.

Activity

  1. added
    bug
    on Jun 12, 2026
  2. ehartford commented on Jul 2, 2026

    @ehartford
    ContributorAuthor

    Fixed by the commit above: Color.Red() (payloadless disc-enum variant in CALL form) now lowers to its repr-backed int constant in MirLower.lower_static_enum_variant_call — the RK_AGGREGATE path was only ever valid for payload-bearing (struct-repr) enums. Pinned by behav_enum_variant_paren_call. §4.4; full gates green.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions