Matching Strada order of operations in recursive signature resolution - #64014
Matching Strada order of operations in recursive signature resolution#64014Ryan 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`.
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 |
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
There was a problem hiding this comment.
That isn't an error in 6.0 either, which makes sense since this is just trying to copy the Strada behavior
There was a problem hiding this comment.
Ye, right - but it errors correctly in Corsa right now. I can open a separate issue about it later - I just wanted to mention the fix here has its drawbacks
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.