-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Andarist
wants to merge
3
commits into
microsoft:main
Choose a base branch
from
Andarist:reuse-errored-signatures
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Show resolved
Hide resolved
|
||
// 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,9 +36700,19 @@ 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 | ||
// | ||
// for the time being only do this when there is a single candidate as the origin index of the `candidatesForArgumentError` is not known | ||
// and it could be different from the selected `bestIndex` here | ||
Comment on lines
+36707
to
+36708
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 |
||
: candidates.length === 1 && candidatesForArgumentError | ||
? candidatesForArgumentError[0] | ||
: inferSignatureInstantiationForOverloadFailure(node, typeParameters, candidate, args, checkMode); | ||
candidates[bestIndex] = instantiated; | ||
return instantiated; | ||
// for similar reasons as above, we reuse the already instantiated *single* candidatesForArgumentError here (even when there are more input candidates) | ||
// this is the preferred candidate for which the signature errors are reported | ||
return candidatesForArgumentError?.length === 1 ? candidatesForArgumentError[0] : instantiated; | ||
} | ||
|
||
function getTypeArgumentsFromNodes(typeArgumentNodes: readonly TypeNode[], typeParameters: readonly TypeParameter[], isJs: boolean): readonly Type[] { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.