-
Notifications
You must be signed in to change notification settings - Fork 13.7k
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
Changes from 2 commits
a1521b0
2f62ee0
99201b2
808220c
3c159d0
bf02bd3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36385,7 +36385,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { | |
| if (result) { | ||
| return result; | ||
| } | ||
| result = getCandidateForOverloadFailure(node, candidates, args, !!candidatesOutArray, checkMode); | ||
| result = getCandidateForOverloadFailure(node, candidates, candidatesForArgumentError, args, !!candidatesOutArray, checkMode); | ||
| // Preemptively cache the result; getResolvedSignature will do this after we return, but | ||
|
Andarist marked this conversation as resolved.
Outdated
|
||
| // we need to ensure that the result is present for the error checks below so that if | ||
| // this signature is encountered again, we handle the circularity (rather than producing a | ||
|
|
@@ -36616,6 +36616,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { | |
| function getCandidateForOverloadFailure( | ||
| node: CallLikeExpression, | ||
| candidates: Signature[], | ||
| candidatesForArgumentError: Signature[] | undefined, | ||
| args: readonly Expression[], | ||
| hasCandidatesOutArray: boolean, | ||
| checkMode: CheckMode, | ||
|
|
@@ -36626,7 +36627,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { | |
| // Don't do this if there is a `candidatesOutArray`, | ||
| // because then we want the chosen best candidate to be one of the overloads, not a combination. | ||
| return hasCandidatesOutArray || candidates.length === 1 || candidates.some(c => !!c.typeParameters) | ||
| ? pickLongestCandidateSignature(node, candidates, args, checkMode) | ||
| ? pickLongestCandidateSignature(node, candidates, candidatesForArgumentError, args, checkMode) | ||
| : createUnionOfSignaturesForOverloadFailure(candidates); | ||
| } | ||
|
|
||
|
|
@@ -36682,7 +36683,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { | |
| return createSymbolWithType(first(sources), type); | ||
| } | ||
|
|
||
| function pickLongestCandidateSignature(node: CallLikeExpression, candidates: Signature[], args: readonly Expression[], checkMode: CheckMode): Signature { | ||
| function pickLongestCandidateSignature(node: CallLikeExpression, candidates: Signature[], candidatesForArgumentError: Signature[] | undefined, args: readonly Expression[], checkMode: CheckMode): Signature { | ||
| // Pick the longest signature. This way we can get a contextual type for cases like: | ||
| // declare function f(a: { xa: number; xb: number; }, b: number); | ||
| // f({ | | ||
|
|
@@ -36699,6 +36700,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { | |
| const typeArgumentNodes: readonly TypeNode[] | undefined = callLikeExpressionMayHaveTypeArguments(node) ? node.typeArguments : undefined; | ||
| const instantiated = typeArgumentNodes | ||
| ? createSignatureInstantiation(candidate, getTypeArgumentsFromNodes(typeArgumentNodes, typeParameters, isInJSFile(node))) | ||
| // when there is only one candidate reuse existing *inferred* candidate for argument error (if available) | ||
| // this saves the compiler some extra work but more importantly it includes inferences made from context-sensitive arguments and generic functions | ||
| // which avoids confusing mismatches between inferred type arguments and reported argument error | ||
| : candidates.length === 1 && candidatesForArgumentError | ||
| ? candidatesForArgumentError[0] | ||
| : inferSignatureInstantiationForOverloadFailure(node, typeParameters, candidate, args, checkMode); | ||
|
Comment on lines
+36885
to
+36886
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd consider revisiting this in Corsa where
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you be convinced to try and port this to Corsa now, just to see?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have I ever come as hard to convince kind of a guy? 😂 |
||
| candidates[bestIndex] = instantiated; | ||
| return instantiated; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.