Skip to content

Add regression test for inference recursion hang - #65362

Merged
Ryan Cavanaugh (RyanCavanaugh) merged 1 commit into
microsoft:mainfrom
yusufyildiz34:fix/64701-infer-type-arguments-regression-test
Nov 6, 2026
Merged

Ryan Cavanaugh (RyanCavanaugh) merged 1 commit into
microsoft:mainfrom
yusufyildiz34:fix/64701-infer-type-arguments-regression-test

Conversation

@yusufyildiz34

@yusufyildiz34 Yusuf YILDIZ (yusufyildiz34) commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #64701

Note

AI disclosure (per CONTRIBUTING.md): I used an AI coding assistant for parts of the investigation, the test reduction and this description. I chose this issue myself, I have reviewed and understood the change, and I will handle review feedback myself.

Analysis

The hang reported in #64701 no longer reproduces on main. It was fixed by #64553 ("Cache inferences made from type arguments"), which did not add a regression test for this scenario.

Verification with the reporter's repro. I ran the equivalent of the reporter's api-probe.cjs against the checker: it requests the return type of every call signature of every expression and its properties.

  • On 5f5dee5b61, the parent of Cache inferences made from type arguments #64553, getReturnTypeOfSignature for the type of vi.mocked(createHandler) did not return within 60s. The stack matches the one in the issue: inferFromTypes → inferFromTypeArguments → inferFromTypes → …
  • On main, all 980 requests complete in about 0.5s.

Root cause. For two instantiations of the same type alias, inferFromTypes infers from their type arguments, and does the same for two references to the same generic type. Before #64553 it called inferFromTypeArguments directly on both paths. #64553 routes both through invokeOnce. invokeOnce skips a source/target pair it has already seen with the same priority and variance, and stops expanding when both sides are deeply nested. In my runs of the reporter's repro, the stack on the parent commit showed the direct calls recursing through nested instantiations of the same aliases.

Reduced repro. In the reporter's setup, the hang was reached through the API (getReturnTypeOfSignature). Their tsc --noEmit run did not request that return type. The source-level form ReturnType<typeof createHandler> reaches the same code path without external packages: getConditionalType → compareSignaturesRelated → instantiateSignatureInContextOf → applyToReturnTypes → inferFromTypes / inferFromTypeArguments. The test is a reduction of the reporter's repro: type-fest's IsEqual is kept as is and vitest is removed.

Note on the expected TS2589. On main the test terminates with TS2589, which the issue lists as acceptable: "report or bail out at the instantiation and depth limits, not loop". TypeScript 5.9.3 and 6.0.3 check this file without errors, though. In my local experiments the difference appears related to TS7's stable type ordering. I reported that separately in #65365, so it is out of scope for this PR.

Fix

There is no compiler change. This PR adds regression coverage for the existing fix: the compiler test inferFromTypeArgumentsNoInfiniteRecursion.ts and its baselines.

What it covers. I tested this by mutating the two call sites in inferFromTypes on main:

Mutation Result
Alias call site (invokeOnce(..., inferFromAliasTypeArguments)) changed to a direct call test times out
Type-reference call site (invokeOnce(..., inferFromReferenceTypeArguments)) changed to a direct call test passes
Both changed test times out

So the test detects removal of the alias-path guard. It does not detect removal of the type-reference-path guard.

Checklist

I successfully ran the applicable commands at the end of my session, and they completed without error:

  • npx hereby validate --all
  • npx hereby tidy && git diff --exit-code

Relating a generic signature to the signature in the `extends` clause of
`ReturnType` instantiates it in the context of that signature. With a
recursive, overload-walking type in its return type, inferring between the
type arguments of nested instantiations of the same type aliases used to
recurse through inferFromTypes and inferFromTypeArguments without
terminating.

microsoft#64553 fixed this by routing inference from type arguments through
invokeOnce, but did not add a regression test for this scenario. The new
test times out on the parent of that commit and passes on main.
Copilot AI balanced review requested due to automatic review settings November 6, 2026 18:17
@typescript-automation typescript-automation Bot added the For Backlog Bug PRs that fix a backlog bug label Nov 6, 2026
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Nov 6, 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.

🟢 Approval recommended

No active review issues were identified for the inference-recursion regression test and its baselines.

No open issues 🎉

What changed in this PR

Adds compiler regression coverage for the inference recursion hang in #64701, already fixed by the inference caching changes in #64553. No compiler implementation changes are included.

Changes:

  • Adds a reduced, dependency-free test that exercises the alias-path recursion guard through ReturnType<typeof createHandler>.
  • Records type, symbol, and diagnostic baselines, including the accepted TS2589 depth-limit error rather than a hang.
File Description
tsc/​testdata/​tests/​cases/​compiler/​inferFromTypeArgumentsNoInfiniteRecursion.ts Adds the reduced inference recursion regression test.
tsc/​testdata/​baselines/​reference/​compiler/​inferFromTypeArgumentsNoInfiniteRecursion.types Records expected inferred types.
tsc/​testdata/​baselines/​reference/​compiler/​inferFromTypeArgumentsNoInfiniteRecursion.symbols Records expected symbol bindings.
tsc/​testdata/​baselines/​reference/​compiler/​inferFromTypeArgumentsNoInfiniteRecursion.errors.txt Records the expected TS2589 diagnostic.

Review effort: Balanced

@github-project-automation github-project-automation Bot moved this from Not started to Needs merge in PR Backlog Nov 6, 2026
@RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh) added this pull request to the merge queue Nov 6, 2026
Merged via the queue into microsoft:main with commit c2f266b Nov 6, 2026
34 checks passed
@github-project-automation github-project-automation Bot moved this from Needs merge to Done in PR Backlog Nov 6, 2026
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: Done

Development

Successfully merging this pull request may close these issues.

typescript-go: Infinite recursion in inferFromTypes via getReturnTypeOfSignature (tsc 5.9 OK)

3 participants