Skip to content

Fix stack overflow caused by simplification of recursive type#4260

Open
ahejlsberg wants to merge 2 commits into
mainfrom
fix-ts-63270
Open

Fix stack overflow caused by simplification of recursive type#4260
ahejlsberg wants to merge 2 commits into
mainfrom
fix-ts-63270

Conversation

@ahejlsberg

Copy link
Copy Markdown
Member

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.

Copilot AI review requested due to automatic review settings June 10, 2026 15:20
@ahejlsberg

ahejlsberg commented Jun 10, 2026

Copy link
Copy Markdown
Member Author

@typescript-bot test this

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 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 getSimplifiedIndexedAccessType to 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.

@jakebailey

Copy link
Copy Markdown
Member

@typescript-bot test it

@jakebailey

Copy link
Copy Markdown
Member

Ah, GitHub outage

@jakebailey

Copy link
Copy Markdown
Member

@typescript-bot test it

1 similar comment
@jakebailey

Copy link
Copy Markdown
Member

@typescript-bot test it

@jakebailey

Copy link
Copy Markdown
Member

@typescript-bot test top800

@typescript-automation

typescript-automation Bot commented Jun 10, 2026

Copy link
Copy Markdown

Starting jobs; this comment will be updated as builds start and complete.

Command Status Results
test top800 ✅ Started ✅ Results

@typescript-automation

Copy link
Copy Markdown

@jakebailey Here are the results of running the top 800 repos with tsc comparing main and refs/pull/4260/merge:

Everything looks good!

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: RangeError: Maximum call stack size exceeded in isRelatedTo with recursive tuple types and spread elements

3 participants