Skip to content

Commit ef0a875

Browse files
committed
Share code a bit better
1 parent afecb87 commit ef0a875

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

src/compiler/checker.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21510,22 +21510,30 @@ namespace ts {
2151021510
// skip the checkApplicableSignature check.
2151121511
if (reportErrors) {
2151221512
if (candidatesForArgumentError) {
21513-
if (candidatesForArgumentError.length > 3) {
21514-
const c = candidatesForArgumentError[candidatesForArgumentError.length - 1];
21515-
const chain = chainDiagnosticMessages(undefined, Diagnostics.Failed_to_find_a_suitable_overload_for_this_call_from_the_0_closest_overloads, candidatesForArgumentError.length);
21516-
21517-
getSignatureApplicabilityError(node, args, c, assignableRelation, CheckMode.Normal, /*reportErrors*/ true, () => chain);
21513+
if (candidatesForArgumentError.length === 1 || candidatesForArgumentError.length > 3) {
21514+
const last = candidatesForArgumentError[candidatesForArgumentError.length - 1];
21515+
let chain: DiagnosticMessageChain | undefined = undefined;
21516+
if (candidatesForArgumentError.length > 3) {
21517+
chain = chainDiagnosticMessages(chain, Diagnostics.The_last_overload_gave_the_following_error);
21518+
chain = chainDiagnosticMessages(chain, Diagnostics.Failed_to_find_a_suitable_overload_for_this_call_from_0_overloads, candidatesForArgumentError.length);
21519+
}
21520+
const r = getSignatureApplicabilityError(node, args, last, assignableRelation, CheckMode.Normal, /*reportErrors*/ true, () => chain);
21521+
Debug.assert(!!r && !!r[0]);
21522+
if (r) {
21523+
diagnostics.add(createDiagnosticForNodeFromMessageChain(r[0], r[1], undefined));
21524+
}
2151821525
}
2151921526
else {
2152021527
const related: DiagnosticRelatedInformation[] = [];
21521-
const close = candidatesForArgumentError.filter(c => getMinArgumentCount(c) <= args.length && args.length <= getParameterCount(c));
21522-
for (const c of close) {
21528+
for (const c of candidatesForArgumentError) {
2152321529
const chain = chainDiagnosticMessages(undefined, Diagnostics.Overload_0_gave_the_following_error, signatureToString(c));
2152421530
const r = getSignatureApplicabilityError(node, args, c, assignableRelation, CheckMode.Normal, /*reportErrors*/ true, () => chain);
21525-
if (!r || !r[0]) continue; // TODO:assert!
21526-
related.push(createDiagnosticForNodeFromMessageChain(r[0], r[1]));
21531+
Debug.assert(!!r && !!r[0]);
21532+
if (r) {
21533+
related.push(createDiagnosticForNodeFromMessageChain(r[0], r[1]));
21534+
}
2152721535
}
21528-
diagnostics.add(createDiagnosticForNodeFromMessageChain(node, chainDiagnosticMessages(undefined, Diagnostics.Failed_to_find_a_suitable_overload_for_this_call_from_the_0_closest_overloads, close.length), related));
21536+
diagnostics.add(createDiagnosticForNodeFromMessageChain(node, chainDiagnosticMessages(undefined, Diagnostics.Failed_to_find_a_suitable_overload_for_this_call_from_0_overloads, candidatesForArgumentError.length), related));
2152921537
}
2153021538
}
2153121539
else if (candidateForArgumentArityError) {

src/compiler/diagnosticMessages.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2621,14 +2621,18 @@
26212621
"category": "Error",
26222622
"code": 2754
26232623
},
2624-
"Failed to find a suitable overload for this call from the {0} closest overloads.": {
2624+
"Failed to find a suitable overload for this call from {0} overloads.": {
26252625
"category": "Error",
26262626
"code": 2755
26272627
},
2628-
"Overload '{0}' gave the following error.": {
2628+
"The last overload gave the following error.": {
26292629
"category": "Error",
26302630
"code": 2756
26312631
},
2632+
"Overload '{0}' gave the following error.": {
2633+
"category": "Error",
2634+
"code": 2757
2635+
},
26322636

26332637
"Import declaration '{0}' is using private name '{1}'.": {
26342638
"category": "Error",

0 commit comments

Comments
 (0)