fix(checker): avoid computed enum member stack overflow - #4603
Open
Zhiyao Wen (ZhiyaoWen999) wants to merge 1 commit into
Open
fix(checker): avoid computed enum member stack overflow#4603Zhiyao Wen (ZhiyaoWen999) wants to merge 1 commit into
Zhiyao Wen (ZhiyaoWen999) wants to merge 1 commit into
Conversation
Author
|
@microsoft-github-policy-service agree |
Contributor
There was a problem hiding this comment.
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
getDeclaredTypeOfEnumby 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Root cause
getDeclaredTypeOfEnumcalledhasBindableNamefor a dynamic computed member name. Determining whether that name was late-bindable checked the computed expression, which resolved an enum member type and re-enteredgetDeclaredTypeOfEnumfor 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=1go test ./... -count=1go vet ./...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