Skip to content

fix(checker): avoid computed enum member stack overflow - #4603

Open
Zhiyao Wen (ZhiyaoWen999) wants to merge 1 commit into
microsoft:mainfrom
ZhiyaoWen999:agent/fix-computed-enum-crash
Open

fix(checker): avoid computed enum member stack overflow#4603
Zhiyao Wen (ZhiyaoWen999) wants to merge 1 commit into
microsoft:mainfrom
ZhiyaoWen999:agent/fix-computed-enum-crash

Conversation

@ZhiyaoWen999

Copy link
Copy Markdown

Summary

  • skip dynamic enum member names while constructing an enum's declared type
  • preserve the existing TS1164 diagnostic for invalid computed enum names
  • add compiler regression coverage and generated type, symbol, and error baselines

Root cause

getDeclaredTypeOfEnum called hasBindableName for a dynamic computed member name. Determining whether that name was late-bindable checked the computed expression, which resolved an enum member type and re-entered getDeclaredTypeOfEnum for the same enum until the goroutine stack overflowed.

Enums do not permit dynamic computed member names, so excluding them from declared-type construction breaks the cycle without changing valid enum behavior. This ports the approach and regression coverage from microsoft/TypeScript#63182 to the Go implementation.

Validation

  • go test ./internal/testrunner -run 'TestLocal/computedEnumMemberKeyNoCrash1' -count=1
  • go test ./... -count=1
  • go vet ./...
  • verified the original repro now reports TS1164 instead of a fatal stack overflow

AI assistance

AI assistance was used to investigate and implement this change. The resulting diff and validation output were reviewed before submission.

Fixes microsoft/TypeScript#63173

@ZhiyaoWen999

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@ZhiyaoWen999
Zhiyao Wen (ZhiyaoWen999) marked this pull request as ready for review July 11, 2026 03:34
Copilot AI review requested due to automatic review settings July 11, 2026 03:34

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.

Pull request overview

This PR fixes a stack overflow in the Go checker when computing an enum’s declared type in the presence of invalid computed (dynamic) enum member names, aligning behavior with upstream TypeScript and preserving the TS1164 diagnostic.

Changes:

  • Avoid re-entering getDeclaredTypeOfEnum by skipping enum members with dynamic names during enum declared-type construction.
  • Add a compiler regression test that previously triggered a crash and now reports TS1164.
  • Add/update reference baselines (types, symbols, errors) for the new regression test.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
testdata/tests/cases/compiler/computedEnumMemberKeyNoCrash1.ts New regression test covering the enum computed-name crash scenario.
testdata/baselines/reference/compiler/computedEnumMemberKeyNoCrash1.types Reference type baseline for the new regression test.
testdata/baselines/reference/compiler/computedEnumMemberKeyNoCrash1.symbols Reference symbol baseline for the new regression test.
testdata/baselines/reference/compiler/computedEnumMemberKeyNoCrash1.errors.txt Reference diagnostic baseline asserting TS1164 is reported (and no crash).
internal/checker/checker.go Fix: exclude dynamically-named enum members from getDeclaredTypeOfEnum construction to prevent recursion/stack overflow.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crash: Maximum call stack size exceeded when declare const enum has a computed property named [object] followed by an object member

2 participants