Skip to content

Commit beddf9c

Browse files
committed
Working, just not the way I would like
There are still separate errors instead of one + related spans for each sub-error.
1 parent c65d9f2 commit beddf9c

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

src/compiler/checker.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21108,8 +21108,11 @@ namespace ts {
2110821108
signature: Signature,
2110921109
relation: Map<RelationComparisonResult>,
2111021110
checkMode: CheckMode,
21111-
reportErrors: boolean) {
21111+
reportErrors: boolean,
21112+
containingMessageChain: (() => DiagnosticMessageChain | undefined) | undefined
21113+
) {
2111221114
if (isJsxOpeningLikeElement(node)) {
21115+
// TODO: Maybe containingMessageChain too?
2111321116
return checkApplicableSignatureForJsxOpeningLikeElement(node, signature, relation, checkMode, reportErrors);
2111421117
}
2111521118
const thisType = getThisTypeOfSignature(signature);
@@ -21137,7 +21140,7 @@ namespace ts {
2113721140
// we obtain the regular type of any object literal arguments because we may not have inferred complete
2113821141
// parameter types yet and therefore excess property checks may yield false positives (see #17041).
2113921142
const checkArgType = checkMode & CheckMode.SkipContextSensitive ? getRegularTypeOfObjectLiteral(argType) : argType;
21140-
if (!checkTypeRelatedToAndOptionallyElaborate(checkArgType, paramType, relation, reportErrors ? arg : undefined, arg, headMessage)) {
21143+
if (!checkTypeRelatedToAndOptionallyElaborate(checkArgType, paramType, relation, reportErrors ? arg : undefined, arg, headMessage, containingMessageChain)) {
2114121144
return false;
2114221145
}
2114321146
}
@@ -21475,11 +21478,14 @@ namespace ts {
2147521478
// skip the checkApplicableSignature check.
2147621479
if (reportErrors) {
2147721480
if (candidatesForArgumentError) {
21478-
createDiagnosticForNodeFromMessageChain // is what I really want to call
21479-
chainDiagnosticMessages(chain, Diagnostics.Failed_to_find_a_suitable_overload_for_this_call);
21480-
diagnostics.add(createDiagnosticForNode(node, Diagnostics.Failed_to_find_a_suitable_overload_for_this_call));
21481+
// const related: DiagnosticRelatedInformation[] = [];
2148121482
for (const c of candidatesForArgumentError) {
21482-
checkApplicableSignature(node, args, c, assignableRelation, CheckMode.Normal, /*reportErrors*/ true);
21483+
const chain = chainDiagnosticMessages(chainDiagnosticMessages(undefined, Diagnostics.Overload_0_gave_the_following_error, signatureToString(c)), Diagnostics.Failed_to_find_a_suitable_overload_for_this_call);
21484+
checkApplicableSignature(node, args, c, assignableRelation, CheckMode.Normal, /*reportErrors*/ true, () => chain);
21485+
// related.push(argNode)
21486+
// This is not right; I want them to be siblings
21487+
// probably this is a new feature :(
21488+
// chain = chainDiagnosticMessages(chain, msg);
2148321489
}
2148421490
}
2148521491
else if (candidateForArgumentArityError) {
@@ -21514,7 +21520,7 @@ namespace ts {
2151421520
if (typeArguments || !hasCorrectArity(node, args, candidate, signatureHelpTrailingComma)) {
2151521521
return undefined;
2151621522
}
21517-
if (!checkApplicableSignature(node, args, candidate, relation, CheckMode.Normal, /*reportErrors*/ false)) {
21523+
if (!checkApplicableSignature(node, args, candidate, relation, CheckMode.Normal, /*reportErrors*/ false, /*containingMessageChain*/ undefined)) {
2151821524
candidatesForArgumentError = [candidate];
2151921525
return undefined;
2152021526
}
@@ -21555,7 +21561,7 @@ namespace ts {
2155521561
else {
2155621562
checkCandidate = candidate;
2155721563
}
21558-
if (!checkApplicableSignature(node, args, checkCandidate, relation, argCheckMode, /*reportErrors*/ false)) {
21564+
if (!checkApplicableSignature(node, args, checkCandidate, relation, argCheckMode, /*reportErrors*/ false, /*containingMessageChain*/ undefined)) {
2155921565
// Give preference to error candidates that have no rest parameters (as they are more specific)
2156021566
if (getMinArgumentCount(checkCandidate) <= args.length && args.length <= getParameterCount(checkCandidate)) {
2156121567
(candidatesForArgumentError || (candidatesForArgumentError = [])).push(checkCandidate);
@@ -21577,7 +21583,7 @@ namespace ts {
2157721583
continue;
2157821584
}
2157921585
}
21580-
if (!checkApplicableSignature(node, args, checkCandidate, relation, argCheckMode, /*reportErrors*/ false)) {
21586+
if (!checkApplicableSignature(node, args, checkCandidate, relation, argCheckMode, /*reportErrors*/ false, /*containingMessageChain*/ undefined)) {
2158121587
// Give preference to error candidates that have no rest parameters (as they are more specific)
2158221588
if (getMinArgumentCount(checkCandidate) <= args.length && args.length <= getParameterCount(checkCandidate)) {
2158321589
(candidatesForArgumentError || (candidatesForArgumentError = [])).push(checkCandidate);

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2625,6 +2625,10 @@
26252625
"category": "Error",
26262626
"code": 2755
26272627
},
2628+
"Overload '{0}' gave the following error.": {
2629+
"category": "Error",
2630+
"code": 2756
2631+
},
26282632

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

0 commit comments

Comments
 (0)