From c65d9f261afa22588ca3f232c98978eee1f82210 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Tue, 18 Jun 2019 08:30:18 -0700 Subject: [PATCH] Initial attempt. Totally doesn't work. --- src/compiler/checker.ts | 23 ++++++++++++++--------- src/compiler/diagnosticMessages.json | 4 ++++ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a4ad3af7d9..77025cd984 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -21439,7 +21439,7 @@ namespace ts { // function foo(): void; // foo(0); // - let candidateForArgumentError: Signature | undefined; + let candidatesForArgumentError: Signature[] | undefined; let candidateForArgumentArityError: Signature | undefined; let candidateForTypeArgumentError: Signature | undefined; let result: Signature | undefined; @@ -21474,8 +21474,13 @@ namespace ts { // If candidate is undefined, it means that no candidates had a suitable arity. In that case, // skip the checkApplicableSignature check. if (reportErrors) { - if (candidateForArgumentError) { - checkApplicableSignature(node, args, candidateForArgumentError, assignableRelation, CheckMode.Normal, /*reportErrors*/ true); + if (candidatesForArgumentError) { + createDiagnosticForNodeFromMessageChain // is what I really want to call + chainDiagnosticMessages(chain, Diagnostics.Failed_to_find_a_suitable_overload_for_this_call); + diagnostics.add(createDiagnosticForNode(node, Diagnostics.Failed_to_find_a_suitable_overload_for_this_call)); + for (const c of candidatesForArgumentError) { + checkApplicableSignature(node, args, c, assignableRelation, CheckMode.Normal, /*reportErrors*/ true); + } } else if (candidateForArgumentArityError) { diagnostics.add(getArgumentArityError(node, [candidateForArgumentArityError], args)); @@ -21500,7 +21505,7 @@ namespace ts { return produceDiagnostics || !args ? resolveErrorCall(node) : getCandidateForOverloadFailure(node, candidates, args, !!candidatesOutArray); function chooseOverload(candidates: Signature[], relation: Map, signatureHelpTrailingComma = false) { - candidateForArgumentError = undefined; + candidatesForArgumentError = undefined; candidateForArgumentArityError = undefined; candidateForTypeArgumentError = undefined; @@ -21510,7 +21515,7 @@ namespace ts { return undefined; } if (!checkApplicableSignature(node, args, candidate, relation, CheckMode.Normal, /*reportErrors*/ false)) { - candidateForArgumentError = candidate; + candidatesForArgumentError = [candidate]; return undefined; } return candidate; @@ -21552,8 +21557,8 @@ namespace ts { } if (!checkApplicableSignature(node, args, checkCandidate, relation, argCheckMode, /*reportErrors*/ false)) { // Give preference to error candidates that have no rest parameters (as they are more specific) - if (!candidateForArgumentError || getEffectiveRestType(candidateForArgumentError) || !getEffectiveRestType(checkCandidate)) { - candidateForArgumentError = checkCandidate; + if (getMinArgumentCount(checkCandidate) <= args.length && args.length <= getParameterCount(checkCandidate)) { + (candidatesForArgumentError || (candidatesForArgumentError = [])).push(checkCandidate); } continue; } @@ -21574,8 +21579,8 @@ namespace ts { } if (!checkApplicableSignature(node, args, checkCandidate, relation, argCheckMode, /*reportErrors*/ false)) { // Give preference to error candidates that have no rest parameters (as they are more specific) - if (!candidateForArgumentError || getEffectiveRestType(candidateForArgumentError) || !getEffectiveRestType(checkCandidate)) { - candidateForArgumentError = checkCandidate; + if (getMinArgumentCount(checkCandidate) <= args.length && args.length <= getParameterCount(checkCandidate)) { + (candidatesForArgumentError || (candidatesForArgumentError = [])).push(checkCandidate); } continue; } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index b209a87880..6393ddd596 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2621,6 +2621,10 @@ "category": "Error", "code": 2754 }, + "Failed to find a suitable overload for this call.": { + "category": "Error", + "code": 2755 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error",