Skip to content

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

Merged
Jake Bailey (jakebailey) merged 11 commits into
microsoft:mainfrom
smg99:fix/issue-64668-enum-memberlist
Nov 20, 2026
Merged

Jake Bailey (jakebailey) merged 11 commits into
microsoft:mainfrom
smg99:fix/issue-64668-enum-memberlist

Conversation

@smg99

@smg99 Sumit G (smg99) commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #64668

Analysis

For a merged namespace and enum, the enum symbol's exports include namespace declarations. In this example, C is a class:

namespace E { export class C {} }
enum E { D = E["C"] }

The element-access path in evaluateEntity checks that E has enum flags, then passes the exported class symbol to evaluateEnumMember. That eventually calls getEnumMemberValue on a class declaration and attempts to compute enum values on its parent module block.

Fix

Require SymbolFlagsEnumMember on the exported symbol before evaluating it as an enum member. This matches the check already used by the identifier and property-access path. Other exports produce the evaluator's existing nonconstant result, allowing the initializer check to report TS18033.

The regression covers the merged namespace and enum case. Removing the previous guard reproduced the KindModuleBlock panic. With the caller check, that regression and the enum compiler suite pass.

Copilot Checklist

  • npx hereby validate

The first full run encountered a file-watcher delete-event timeout. That test passed three retries, the complete compiler test suite passed on rerun, and the final full validation passed.

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 Resolved
@smg99

Copy link
Copy Markdown
Contributor 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
Contributor Author

@microsoft-github-policy-service agree

@smg99

Copy link
Copy Markdown
Contributor 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.

@smg99

Copy link
Copy Markdown
Contributor Author

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

Signed LCA, Can you please review? Jake Bailey (@jakebailey)

Comment thread tsc/internal/checker/checker.go Resolved
@github-project-automation github-project-automation Bot moved this from Not started to Needs merge in PR Backlog Nov 20, 2026
@jakebailey
Jake Bailey (jakebailey) added this pull request to the merge queue Nov 20, 2026
Merged via the queue into microsoft:main with commit 1d0c7e9 Nov 20, 2026
34 checks passed
@github-project-automation github-project-automation Bot moved this from Needs merge to Done in PR Backlog Nov 20, 2026
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: Done

Development

Successfully merging this pull request may close these issues.

panic: Unhandled case in Node.MemberList

3 participants