fix: support fully-qualified enum values in switch when clauses#88
Merged
Conversation
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
Contributor
|
@codex review |
|
Codex Review: Didn't find any major issues. Bravo. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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
approved these changes
Apr 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #63. Changes
whenLiteralin the grammar to matchqualifiedNamein place ofid, so dotted enum references likewhen MyEnum.VALUEandwhen MyClass.MyEnum.VALUEparse.Previously these failed: the parser picked the
typeRef idalternative and lettypeRefgreedily consume the entire dotted chain, leaving no trailing identifier to satisfy theidslot.AST shape note
when VALUE {}still parses cleanly, but now producesWhenLiteral > qualifiedName > idrather thanWhenLiteral > id. Tree-walking consumers that descend intoWhenLiteralwill need to account for the extraqualifiedNamenode. 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, sowhen MyEnum.VALUE {}→ whenLiteral andwhen 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 newtestWhenQualifiedEnumValuemvn test(jvm) — 74/74 pass (was 73), including newtestWhenQualifiedEnumValueMyEnum.VALUE,MyClass.MyEnum.VALUE, comma-separated dotted enums all parse;Account acc,ns.Account acc, literals,null,elseall unchangednpm run lintclean