Skip to content

fix: support fully-qualified enum values in switch when clauses#88

Merged
nawforce merged 1 commit into
mainfrom
fix/issue-63-qualified-enum-when
Apr 23, 2026
Merged

fix: support fully-qualified enum values in switch when clauses#88
nawforce merged 1 commit into
mainfrom
fix/issue-63-qualified-enum-when

Conversation

@kjonescertinia

Copy link
Copy Markdown
Contributor

Summary

Fixes #63. Changes whenLiteral in the grammar to match qualifiedName in place of id, so dotted enum references like when MyEnum.VALUE and when MyClass.MyEnum.VALUE parse.

Previously these failed: the parser picked the typeRef id alternative and let typeRef greedily consume the entire dotted chain, leaving no trailing identifier to satisfy the id slot.

AST shape note

when VALUE {} still parses cleanly, but now produces WhenLiteral > qualifiedName > id rather than WhenLiteral > id. Tree-walking consumers that descend into WhenLiteral will need to account for the extra qualifiedName node. Flagged in CHANGELOG.

Semantic note

The grammar does not syntactically disambiguate when Foo {} — it could be an enum constant or a class-constant reference. That was true before this change as well and is unavoidable without type information. The only ambiguity this change introduces is between dotted enum values (whenLiteral) and namespaced SObject bindings (typeRef id) — LL(*) prediction picks the correct alternative based on whether a trailing bare identifier is present, so when MyEnum.VALUE {} → whenLiteral and when ns.Account acc {} → typeRef id.

Precedent

Grammar corrections have historically shipped in minor/patch versions. The closest prior is 4.3.1: "Fix parser whenValue to support type refs". Targeting 5.1.0.

Test plan

  • npm test — 75/75 pass (was 74), including new testWhenQualifiedEnumValue
  • mvn test (jvm) — 74/74 pass (was 73), including new testWhenQualifiedEnumValue
  • Manual probe: MyEnum.VALUE, MyClass.MyEnum.VALUE, comma-separated dotted enums all parse; Account acc, ns.Account acc, literals, null, else all unchanged
  • npm run lint clean

Change `whenLiteral` to match `qualifiedName` in place of `id` so that
dotted enum references like `when MyEnum.VALUE` and
`when MyClass.MyEnum.VALUE` parse. Previously these failed because
the parser picked the `typeRef id` alternative and consumed the entire
dotted chain as the type, leaving no trailing identifier.

AST note: `when VALUE {}` now produces
`WhenLiteral > qualifiedName > id` rather than `WhenLiteral > id`.

Fixes #63
@nawforce

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@nawforce nawforce merged commit 62344b0 into main Apr 23, 2026
1 check passed
@nawforce nawforce deleted the fix/issue-63-qualified-enum-when branch April 23, 2026 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Switch statement fully qualified enum type name

2 participants