Matching Strada order of operations in recursive signature resolution - #64014
Open
Ryan Cavanaugh (RyanCavanaugh) wants to merge 1 commit into
Open
Matching Strada order of operations in recursive signature resolution#64014Ryan Cavanaugh (RyanCavanaugh) wants to merge 1 commit into
Ryan Cavanaugh (RyanCavanaugh) wants to merge 1 commit into
Conversation
(Copilot fix + manual guidance)
When resolving a nested generic call inside a callback passed to another generic function, signature resolution can reenter for the same call node. The recursive resolution computes and caches the correct source-order signature.
The Go checker still reused this cached signature late in `getResolvedSignature`. By that point, the local resolution had already used an incomplete contextual type derived from the containing callback. This allowed the callback’s inferred `string` return type to flow backward into the nested call:
```ts
identity((data: { value: number }) => request(data));
```
`request` consequently inferred `T = string` instead of applying its default type, making its parameter type `undefined` and producing TS2345.
Current Strada handles this reentrancy earlier in `resolveCall`, returning the recursively cached source-order signature before the incomplete contextual result can affect resolution.
Ports Strada’s current resolved-signature caching behavior:
- Prefer a recursively cached source-order signature in `resolveCall`.
- Remove the obsolete late replacement in `getResolvedSignature`.
Copilot started reviewing on behalf of
Ryan Cavanaugh (RyanCavanaugh)
August 25, 2026 19:36
View session
Contributor
There was a problem hiding this comment.
Pull request overview
Aligns recursive signature resolution with Strada, preventing incomplete contextual types from overriding correctly cached signatures.
Changes:
- Reuses cached signatures earlier in
resolveCall. - Adds regression coverage for generic defaults in callbacks.
- Records expected symbol and type baselines.
Show a summary per file
| File | Description |
|---|---|
tsc/internal/checker/checker.go |
Moves cached-signature handling into call resolution. |
tsc/testdata/tests/cases/compiler/genericDefaultInContextSensitiveCallback.ts |
Adds the regression test. |
tsc/testdata/baselines/reference/compiler/genericDefaultInContextSensitiveCallback.types |
Verifies inferred types. |
tsc/testdata/baselines/reference/compiler/genericDefaultInContextSensitiveCallback.symbols |
Records symbol resolution. |
Review details
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
- Files reviewed: 4/4 changed files
- Comments generated: 0
- Review effort level: Balanced
| // Signature resolution may reenter for the same node and cache the source-order result. | ||
| // Prefer that result over one computed using an incomplete contextual type. | ||
| debug.Assert(links.resolvedSignature != nil) | ||
| return links.resolvedSignature |
Contributor
There was a problem hiding this comment.
Moving it like this here breaks:
declare const example: (f: (a: string) => number) => string;
const f = (a: string) => g();
const g = () => {
return example(f);
};The above should error but IIRC it doesn't with this fix. Note that I'm mainly speaking from my memory right now - but this change basically ports my own #60208 and I was looking into this whole issue yesterday (and still thinking about how to fix it to satisfy all the cases) so I hope my memory serves me well ;p
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.
Fixes #63949
(Copilot fix + manual guidance)
When resolving a nested generic call inside a callback passed to another generic function, signature resolution can reenter for the same call node. The recursive resolution computes and caches the correct source-order signature.
The Go checker still reused this cached signature late in
getResolvedSignature. By that point, the local resolution had already used an incomplete contextual type derived from the containing callback. This allowed the callback’s inferredstringreturn type to flow backward into the nested call:requestconsequently inferredT = stringinstead of applying its default type, making its parameter typeundefinedand producing TS2345.Current Strada handles this reentrancy earlier in
resolveCall, returning the recursively cached source-order signature before the incomplete contextual result can affect resolution.