Repository navigation
Fix enum crash when namespace and enum share a name - #64743
Sumit G (smg99) wants to merge 4 commits into
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
The unrelated ModuleBlock member-list expansion weakens an established AST API invariant.
1 open finding
What changed in this PR
Prevents a compiler panic when merged namespace/enum member access reaches enum value computation.
Changes:
- Guards enum computation by node kind.
- Expands
MemberListto module blocks. - Adds regression coverage and baselines.
| File | Description |
|---|---|
tsc/internal/checker/checker.go |
Guards enum value computation. |
tsc/internal/ast/ast.go |
Adds module blocks to MemberList. |
tsc/testdata/tests/cases/compiler/enumMemberListModuleBlock.ts |
Adds regression case. |
tsc/testdata/baselines/reference/compiler/enumMemberListModuleBlock.errors.txt |
Captures expected diagnostic. |
tsc/testdata/baselines/reference/compiler/enumMemberListModuleBlock.js |
Captures emitted JavaScript. |
tsc/testdata/baselines/reference/compiler/enumMemberListModuleBlock.symbols |
Captures symbol output. |
tsc/testdata/baselines/reference/compiler/enumMemberListModuleBlock.types |
Captures type output. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
| case KindEnumDeclaration: | ||
| return n.AsEnumDeclaration().Members | ||
| case KindModuleBlock: | ||
| return n.AsModuleBlock().Statements | ||
| case KindTypeLiteral: |
|
Addressed the AST API invariant review: removed the unrelated |
|
If you're not a person who can sign a CLA, I don't think you should be sending PRs |
|
@microsoft-github-policy-service agree |
|
To clarify: I am submitting this PR personally, as an independent individual contributor, not on behalf of my employer or any company. I can sign the Microsoft CLA in my individual capacity if GitHub still requires it; please let me know if any contributor verification remains outstanding. The earlier AST MemberList review finding has already been addressed in d064a4c. |

Fixes #64668
Problem
The compiler could panic when a namespace and enum shared the same name and the enum initializer accessed a member from the namespace object.
Fix
EnumDeclarationnodes.ModuleBlockas a member container for generic member-list access to avoid falling through to a non-enum node.Validation
cd tsc && go test -run 'TestLocal/enumMemberListModuleBlock' ./internal/testrunnergo build -o /tmp/tsc ./cmd/tsc && /tmp/tsc /tmp/ts_memberlist_bug.ts, which now emits the expectedTS18033diagnostic instead of panicking.AI disclosure
This PR was authored with GitHub Copilot assistance and reviewed before submission.