Fix stack overflow caused by simplification of recursive type#4260
Open
ahejlsberg wants to merge 2 commits into
Open
Fix stack overflow caused by simplification of recursive type#4260ahejlsberg wants to merge 2 commits into
ahejlsberg wants to merge 2 commits into
Conversation
Member
Author
|
@typescript-bot test this |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR prevents infinite recursion/stack overflows in the type checker when simplifying certain recursive indexed access types by removing the original indexed access type from a simplified union result when it appears as a constituent (fixing microsoft/TypeScript#63270).
Changes:
- Refactored
getSimplifiedIndexedAccessTypeto compute the simplified form via a worker and post-process the result to drop self-references from union simplifications. - Added a compiler regression test that previously could trigger unbounded recursion in type inference/relations, along with expected baselines.
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 |
|---|---|
internal/checker/checker.go |
Refactors indexed-access simplification and removes self-referential constituents from simplified union results to avoid recursion. |
testdata/tests/cases/compiler/recursiveIndexedAccessSimplification.ts |
New regression test case based on the upstream issue repro. |
testdata/baselines/reference/compiler/recursiveIndexedAccessSimplification.errors.txt |
Expected diagnostics baseline for the new test. |
testdata/baselines/reference/compiler/recursiveIndexedAccessSimplification.types |
Expected types baseline for the new test. |
testdata/baselines/reference/compiler/recursiveIndexedAccessSimplification.symbols |
Expected symbols baseline for the new test. |
Member
|
@typescript-bot test it |
Member
|
Ah, GitHub outage |
Member
|
@typescript-bot test it |
1 similar comment
Member
|
@typescript-bot test it |
Member
|
@typescript-bot test top800 |
|
@jakebailey Here are the results of running the top 800 repos with tsc comparing Everything looks good! |
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.
With this PR, when simplification of an indexed access type leads to a union type that contains that same indexed access type, we remove the indexed access type from the union type. This fixes infinite recursion that could otherwise occur in type inference and type relations.
Fixes microsoft/TypeScript#63270.