Skip to content

Matching Strada order of operations in recursive signature resolution - #64014

Open
Ryan Cavanaugh (RyanCavanaugh) wants to merge 1 commit into
microsoft:mainfrom
RyanCavanaugh:fix63949
Open

Matching Strada order of operations in recursive signature resolution#64014
Ryan Cavanaugh (RyanCavanaugh) wants to merge 1 commit into
microsoft:mainfrom
RyanCavanaugh:fix63949

Conversation

@RyanCavanaugh

Copy link
Copy Markdown
Member

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:

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.

(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 AI balanced review requested due to automatic review settings August 25, 2026 19:35
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Aug 25, 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.

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

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.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

[7.0 regression] Type parameter default is ignored when the call sits inside a callback passed to a generic function

3 participants