From ef0a8759bd66c10df53b0c0a76c33eadf62462fb Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Thu, 20 Jun 2019 15:40:29 -0700 Subject: [PATCH] Share code a bit better --- src/compiler/checker.ts | 28 ++++++++++++++++++---------- src/compiler/diagnosticMessages.json | 8 ++++++-- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index bad283bb1c..a177fd3522 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -21510,22 +21510,30 @@ namespace ts { // skip the checkApplicableSignature check. if (reportErrors) { if (candidatesForArgumentError) { - if (candidatesForArgumentError.length > 3) { - const c = candidatesForArgumentError[candidatesForArgumentError.length - 1]; - const chain = chainDiagnosticMessages(undefined, Diagnostics.Failed_to_find_a_suitable_overload_for_this_call_from_the_0_closest_overloads, candidatesForArgumentError.length); - - getSignatureApplicabilityError(node, args, c, assignableRelation, CheckMode.Normal, /*reportErrors*/ true, () => chain); + if (candidatesForArgumentError.length === 1 || candidatesForArgumentError.length > 3) { + const last = candidatesForArgumentError[candidatesForArgumentError.length - 1]; + let chain: DiagnosticMessageChain | undefined = undefined; + if (candidatesForArgumentError.length > 3) { + chain = chainDiagnosticMessages(chain, Diagnostics.The_last_overload_gave_the_following_error); + chain = chainDiagnosticMessages(chain, Diagnostics.Failed_to_find_a_suitable_overload_for_this_call_from_0_overloads, candidatesForArgumentError.length); + } + const r = getSignatureApplicabilityError(node, args, last, assignableRelation, CheckMode.Normal, /*reportErrors*/ true, () => chain); + Debug.assert(!!r && !!r[0]); + if (r) { + diagnostics.add(createDiagnosticForNodeFromMessageChain(r[0], r[1], undefined)); + } } else { const related: DiagnosticRelatedInformation[] = []; - const close = candidatesForArgumentError.filter(c => getMinArgumentCount(c) <= args.length && args.length <= getParameterCount(c)); - for (const c of close) { + for (const c of candidatesForArgumentError) { const chain = chainDiagnosticMessages(undefined, Diagnostics.Overload_0_gave_the_following_error, signatureToString(c)); const r = getSignatureApplicabilityError(node, args, c, assignableRelation, CheckMode.Normal, /*reportErrors*/ true, () => chain); - if (!r || !r[0]) continue; // TODO:assert! - related.push(createDiagnosticForNodeFromMessageChain(r[0], r[1])); + Debug.assert(!!r && !!r[0]); + if (r) { + related.push(createDiagnosticForNodeFromMessageChain(r[0], r[1])); + } } - diagnostics.add(createDiagnosticForNodeFromMessageChain(node, chainDiagnosticMessages(undefined, Diagnostics.Failed_to_find_a_suitable_overload_for_this_call_from_the_0_closest_overloads, close.length), related)); + diagnostics.add(createDiagnosticForNodeFromMessageChain(node, chainDiagnosticMessages(undefined, Diagnostics.Failed_to_find_a_suitable_overload_for_this_call_from_0_overloads, candidatesForArgumentError.length), related)); } } else if (candidateForArgumentArityError) { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index baa0a5fa14..b2ba98c586 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2621,14 +2621,18 @@ "category": "Error", "code": 2754 }, - "Failed to find a suitable overload for this call from the {0} closest overloads.": { + "Failed to find a suitable overload for this call from {0} overloads.": { "category": "Error", "code": 2755 }, - "Overload '{0}' gave the following error.": { + "The last overload gave the following error.": { "category": "Error", "code": 2756 }, + "Overload '{0}' gave the following error.": { + "category": "Error", + "code": 2757 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error",