Skip to content

Fix enum crash when namespace and enum share a name - #64743

Open
Sumit G (smg99) wants to merge 4 commits into
microsoft:mainfrom
smg99:fix/issue-64668-enum-memberlist
Open

Sumit G (smg99) wants to merge 4 commits into
microsoft:mainfrom
smg99:fix/issue-64668-enum-memberlist

Conversation

@smg99

Copy link
Copy Markdown

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

  • Guard enum value computation so it only runs for actual EnumDeclaration nodes.
  • Treat ModuleBlock as a member container for generic member-list access to avoid falling through to a non-enum node.
  • Added a regression test covering the merged namespace/enum case.

Validation

  • cd tsc && go test -run 'TestLocal/enumMemberListModuleBlock' ./internal/testrunner
  • Reproduced the original crash before the fix with go build -o /tmp/tsc ./cmd/tsc && /tmp/tsc /tmp/ts_memberlist_bug.ts, which now emits the expected TS18033 diagnostic instead of panicking.

AI disclosure

This PR was authored with GitHub Copilot assistance and reviewed before submission.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 12, 2026 04:55
@typescript-automation typescript-automation Bot added the For Backlog Bug PRs that fix a backlog bug label Oct 12, 2026
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Oct 12, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 MemberList to 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.

Comment thread tsc/internal/ast/ast.go
Comment on lines 564 to 568
case KindEnumDeclaration:
return n.AsEnumDeclaration().Members
case KindModuleBlock:
return n.AsModuleBlock().Statements
case KindTypeLiteral:
@smg99

Copy link
Copy Markdown
Author

Addressed the AST API invariant review: removed the unrelated KindModuleBlock branch from Node.MemberList() in commit d064a4c, retaining only the targeted enum guard and regression case. The Microsoft CLA remains pending contributor authorization; I have not accepted it automatically.

@jakebailey

Copy link
Copy Markdown
Member

If you're not a person who can sign a CLA, I don't think you should be sending PRs

@smg99

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@smg99

Copy link
Copy Markdown
Author

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.

This branch has not been deployed

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

Labels

For Backlog Bug PRs that fix a backlog bug

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

panic: Unhandled case in Node.MemberList

3 participants