Skip to content

Reuse single errored signature candidate as resolved signature #61787

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Andarist
Copy link
Contributor

fixes #61500

@Copilot Copilot AI review requested due to automatic review settings May 30, 2025 19:53
@github-project-automation github-project-automation bot moved this to Not started in PR Backlog May 30, 2025
@typescript-bot typescript-bot added the For Backlog Bug PRs that fix a backlog bug label May 30, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances overload resolution by reusing a single errored signature candidate as the resolved signature and updates tests and baselines accordingly.

  • Adjust overload failure logic in checker.ts to prefer a lone errored candidate
  • Add new fourslash tests for failed inference in context-sensitive arguments
  • Update numerous baseline reference files to reflect the new signature resolution behavior

Reviewed Changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/compiler/checker.ts Adjust candidate selection to reuse a single errored signature
tests/cases/fourslash/quickInfoFailedInferenceWithContextSensitiveArg2.ts Add quickInfo test for second context-sensitive failure scenario
tests/cases/fourslash/quickInfoFailedInferenceWithContextSensitiveArg1.ts Add quickInfo test for first context-sensitive failure scenario
tests/cases/fourslash/completionsFailedInferenceWithContextSensitiveArg1.ts Add completion test for context-sensitive inference failure
tests/cases/conformance/types/typeRelationships/typeInference/contextualSignatureInstantiation.ts Update test to use baz signature reuse with explicit b2
tests/baselines/reference/promiseTry.types Update expected return type for Promise.try
tests/baselines/reference/promisePermutations3.types Update expected IPromise chaining result
tests/baselines/reference/partiallyAnnotatedFunctionInferenceError.types Revise expected inference error outputs
tests/baselines/reference/genericCallWithFunctionTypedArguments5.types Correct expected return type from function-typed argument calls
tests/baselines/reference/generatorTypeCheck62.types Update expected strategy generator signature
tests/baselines/reference/contextualSignatureInstantiation.types Reflect new baz return types and renamed b2
tests/baselines/reference/contextualSignatureInstantiation.symbols Update symbol declarations for b2 and d vars
tests/baselines/reference/contextualSignatureInstantiation.js Adjust JS baseline for b2 and d variable initializations
tests/baselines/reference/contextualSignatureInstantiation.errors.txt Update error messages and variable names from b to b2

@Andarist Andarist marked this pull request as draft May 30, 2025 20:54
@Andarist Andarist marked this pull request as ready for review May 31, 2025 08:27
@@ -33,8 +33,8 @@ declare function testError<T extends C>(a: (t: T, t1: T) => void): T

// more args
testError((t1: D, t2, t3) => {})
>testError((t1: D, t2, t3) => {}) : C
> : ^
>testError((t1: D, t2, t3) => {}) : any
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks bad but this call errors so I think it's a fair game that the returned type changes - as it doesn't quite matter anyway.

The reason it got changed is simple - this got inferred from the implicit any assigned to t2 and t3. The same was always inferred here internally. It's just the final assigned signature was the one computed by inferSignatureInstantiationForOverloadFailure and that ignores context--sensitive arguments.

All of the changes in baselines can be attributed to the same thing. It's just any here is, of course, extra suspicious.

Maybe this could be "improved" but given this callback has more parameters than the contextual signature - the contextual signature is not selected so it can't assign "better" types to t2 and t3. This gets ignored in getContextualCallSignature based on the isAritySmaller check.

Comment on lines +23 to +24
var b2: number | string;
var b2 = baz(b2, b2, g); // Should be number | string
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the change here? it's because now the previous calls are able to change the assigned type to b (by not ignoring generic functions we infer string/number instead of unknown). So the contextual return type here changed from string | number to string and that introduced the error. But that never was the intention of this test case anyway - so I just separated this to decouple this from CFA type changes

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: Not started
Development

Successfully merging this pull request may close these issues.

Broken Autocomplete and Type Display For Parameters Dependent on Transitively Contextually Typed Return Type
2 participants