Skip to content

fix: Fix MemberList panic on merged enum element access - #64746

Open
Andre Fajar N (andre-fajar-n) wants to merge 3 commits into
microsoft:mainfrom
andre-fajar-n:fix/memberlist-moduleblock-panic
Open

Andre Fajar N (andre-fajar-n) wants to merge 3 commits into
microsoft:mainfrom
andre-fajar-n:fix/memberlist-moduleblock-panic

Conversation

@andre-fajar-n

Copy link
Copy Markdown
Contributor

Fixes #64668
AI assistance disclosure: This patch was authored with Cursor (AI coding agent). I
have read and understood the change, and I will shepherd review and revisions myself.

Analysis

When an enum and a namespace share a name, element access like E["C"] in an enum
member initializer can resolve a namespace export (e.g. a class) via
rootSymbol.Exports()[name].
The element-access path in evaluateEntity treated any non-nil export as an enum member
and called getEnumMemberValue → computeEnumMemberValues(node.Parent) → Members().
For a class declaration, Parent is a ModuleBlock, so Node.MemberList panicked:
panic: Unhandled case in Node.MemberList: KindModuleBlock
Repro:

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

The identifier/property-access path already requires SymbolFlagsEnumMember; element
access did not.

Fix

In evaluateEntity's KindElementAccessExpression branch, only constant-evaluate when
the export has SymbolFlagsEnumMember (same guard as the identifier path).
Non-enum-member exports fall through to a non-constant result and produce a normal
diagnostic (TS18033) instead of crashing.
Alternate considered: widening Node.MemberList to accept KindModuleBlock — rejected;
the bug is incorrect enum evaluation, not a missing AST list case.

Copilot AI balanced review requested due to automatic review settings October 12, 2026 07:51
@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
@andre-fajar-n Andre Fajar N (andre-fajar-n) changed the title fix: Fix MemberList panic on enum element access with merged namespac… fix: Fix MemberList panic on merged enum element access 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

Alias exports targeting enum members must be resolved before applying the new flag guard.

1 open finding
What changed in this PR

Prevents a compiler panic when bracket access resolves to a non-enum export on a merged enum/namespace.

Changes:

  • Guards enum evaluation with SymbolFlagsEnumMember.
  • Adds a regression test and diagnostic, emit, type, and symbol baselines.
File Description
tsc/​internal/​checker/​checker.go Restricts bracket-access enum evaluation.
tsc/​testdata/​tests/​cases/​compiler/​enumInitializerNamespaceExportElementAccess.ts Adds the crash regression case.
tsc/​testdata/​baselines/​reference/​compiler/​enumInitializerNamespaceExportElementAccess.errors.txt Records TS18033.
tsc/​testdata/​baselines/​reference/​compiler/​enumInitializerNamespaceExportElementAccess.js Records emitted JavaScript.
tsc/​testdata/​baselines/​reference/​compiler/​enumInitializerNamespaceExportElementAccess.symbols Records resolved symbols.
tsc/​testdata/​baselines/​reference/​compiler/​enumInitializerNamespaceExportElementAccess.types Records inferred types.

🧠 Review effort: Balanced


💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment thread tsc/internal/checker/checker.go Outdated

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.

🟢 Approval recommended

The guard fixes the panic while preserving aliased enum-member evaluation with focused regression coverage.

0 open findings

1 resolved since last review

🧠 Review effort: Balanced

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

2 participants