| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
(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.
Aligns recursive signature resolution with Strada, preventing incomplete contextual types from overriding correctly cached signatures.
Changes:
| 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. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Sorry, something went wrong.
| // 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
Sorry, something went wrong.
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
Sorry, something went wrong.
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
Sorry, something went wrong.
There was a problem hiding this comment.
Here is my take on the fix for this whole issue without introducing this regression: #64077
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
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 inferred string return type to flow backward into the nested call:
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.