Skip to content

Commit 1f6ef05

Browse files
committed
Re-add multiple errors
In the worst possible way. Now it's sort of ready for creating a DiagnosticMessageTree.
1 parent e5fd876 commit 1f6ef05

File tree

1 file changed

+27
-18
lines changed

1 file changed

+27
-18
lines changed

src/compiler/checker.ts

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11671,12 +11671,14 @@ namespace ts {
1167111671
return checkTypeRelatedToAndOptionallyElaborate(source, target, assignableRelation, errorNode, expr, headMessage, containingMessageChain);
1167211672
}
1167311673

11674-
function checkTypeRelatedToAndOptionallyElaborate(source: Type, target: Type, relation: Map<RelationComparisonResult>, errorNode: Node | undefined, expr: Expression | undefined, headMessage?: DiagnosticMessage, containingMessageChain?: () => DiagnosticMessageChain | undefined): boolean {
11675-
if (isTypeRelatedTo(source, target, relation)) return true;
11674+
function checkTypeRelatedToAndOptionallyElaborate(source: Type, target: Type, relation: Map<RelationComparisonResult>, errorNode: Node | undefined, expr: Expression | undefined, headMessage?: DiagnosticMessage, containingMessageChain?: () => DiagnosticMessageChain | undefined): boolean;
11675+
function checkTypeRelatedToAndOptionallyElaborate(source: Type, target: Type, relation: Map<RelationComparisonResult>, errorNode: Node | undefined, expr: Expression | undefined, headMessage?: DiagnosticMessage, containingMessageChain?: () => DiagnosticMessageChain | undefined, breakdown?: boolean): [Node, DiagnosticMessageChain];
11676+
function checkTypeRelatedToAndOptionallyElaborate(source: Type, target: Type, relation: Map<RelationComparisonResult>, errorNode: Node | undefined, expr: Expression | undefined, headMessage?: DiagnosticMessage, containingMessageChain?: () => DiagnosticMessageChain | undefined, breakdown?: boolean): boolean | [Node, DiagnosticMessageChain] {
11677+
if (isTypeRelatedTo(source, target, relation)) return breakdown ? false : true;
1167611678
if (!errorNode || !elaborateError(expr, source, target, relation, headMessage)) {
11677-
return checkTypeRelatedTo(source, target, relation, errorNode, headMessage, containingMessageChain);
11679+
return checkTypeRelatedTo(source, target, relation, errorNode, headMessage, containingMessageChain, undefined, breakdown);
1167811680
}
11679-
return false;
11681+
return breakdown ? [undefined!,undefined!] as [Node, DiagnosticMessageChain] : false;
1168011682
}
1168111683

1168211684
function isOrHasGenericConditional(type: Type): boolean {
@@ -12430,7 +12432,10 @@ namespace ts {
1243012432
}
1243112433
diagnostics.add(diag); // TODO: GH#18217
1243212434
}
12433-
Debug.assert(!breakdown);
12435+
if (breakdown) {
12436+
Debug.assert(result === Ternary.False ? !errorNode : true, "missed opportunity to interact with error.");
12437+
return result === Ternary.False ? [undefined!, undefined!] as [Node, DiagnosticMessageChain] : false;
12438+
}
1243412439
return result !== Ternary.False;
1243512440

1243612441
function reportError(message: DiagnosticMessage, arg0?: string | number, arg1?: string | number, arg2?: string | number, arg3?: string | number): void {
@@ -21121,13 +21126,13 @@ namespace ts {
2112121126
// can be specified by users through attributes property.
2112221127
const paramType = getEffectiveFirstArgumentForJsxSignature(signature, node);
2112321128
const attributesType = checkExpressionWithContextualType(node.attributes, paramType, /*inferenceContext*/ undefined, checkMode);
21124-
return checkTypeRelatedToAndOptionallyElaborate(attributesType, paramType, relation, reportErrors ? node.tagName : undefined, node.attributes);
21129+
return checkTypeRelatedToAndOptionallyElaborate(attributesType, paramType, relation, reportErrors ? node.tagName : undefined, node.attributes, undefined, undefined, /*breakdown*/ true);
2112521130
}
2112621131

2112721132
// TODO: This function is only used in overload resolution; it should instead return a [errorNode, messageChain] pair if there is a failure and undefined if not
2112821133
// The first-round callers can used undefined=pass and the second-round callers can build their own errors from the pair.
2112921134
// TODO: Still need to thread BREAKDOWN through checkTypeRealtedToAndOptionallyElaborate and all other checkType calls
21130-
function checkApplicableSignature(
21135+
function getSignatureApplicabilityError(
2113121136
node: CallLikeExpression,
2113221137
args: ReadonlyArray<Expression>,
2113321138
signature: Signature,
@@ -21149,8 +21154,9 @@ namespace ts {
2114921154
const thisArgumentType = thisArgumentNode ? checkExpression(thisArgumentNode) : voidType;
2115021155
const errorNode = reportErrors ? (thisArgumentNode || node) : undefined;
2115121156
const headMessage = Diagnostics.The_this_context_of_type_0_is_not_assignable_to_method_s_this_of_type_1;
21152-
if (!checkTypeRelatedTo(thisArgumentType, thisType, relation, errorNode, headMessage)) {
21153-
return false;
21157+
const r = checkTypeRelatedTo(thisArgumentType, thisType, relation, errorNode, headMessage, undefined, undefined, /*breakdown*/ true);
21158+
if (r) {
21159+
return r;
2115421160
}
2115521161
}
2115621162
const headMessage = Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1;
@@ -21165,17 +21171,18 @@ namespace ts {
2116521171
// we obtain the regular type of any object literal arguments because we may not have inferred complete
2116621172
// parameter types yet and therefore excess property checks may yield false positives (see #17041).
2116721173
const checkArgType = checkMode & CheckMode.SkipContextSensitive ? getRegularTypeOfObjectLiteral(argType) : argType;
21168-
if (!checkTypeRelatedToAndOptionallyElaborate(checkArgType, paramType, relation, reportErrors ? arg : undefined, arg, headMessage, containingMessageChain)) {
21169-
return false;
21174+
const r = checkTypeRelatedToAndOptionallyElaborate(checkArgType, paramType, relation, reportErrors ? arg : undefined, arg, headMessage, containingMessageChain, /*breakdown*/ true);
21175+
if (r) {
21176+
return r;
2117021177
}
2117121178
}
2117221179
}
2117321180
if (restType) {
2117421181
const spreadType = getSpreadArgumentType(args, argCount, args.length, restType, /*context*/ undefined);
2117521182
const errorNode = reportErrors ? argCount < args.length ? args[argCount] : node : undefined;
21176-
return checkTypeRelatedTo(spreadType, restType, relation, errorNode, headMessage);
21183+
return checkTypeRelatedTo(spreadType, restType, relation, errorNode, headMessage, undefined, undefined, /*breakdown*/ true);
2117721184
}
21178-
return true;
21185+
return undefined;
2117921186
}
2118021187

2118121188
/**
@@ -21506,13 +21513,15 @@ namespace ts {
2150621513
if (candidatesForArgumentError.length > 3) {
2150721514
const c = candidatesForArgumentError[candidatesForArgumentError.length - 1];
2150821515
const chain = chainDiagnosticMessages(undefined, Diagnostics.Failed_to_find_a_suitable_overload_for_this_call);
21509-
checkApplicableSignature(node, args, c, assignableRelation, CheckMode.Normal, /*reportErrors*/ true, () => chain);
21516+
getSignatureApplicabilityError(node, args, c, assignableRelation, CheckMode.Normal, /*reportErrors*/ true, () => chain);
2151021517
}
2151121518
else {
2151221519
// const related: DiagnosticRelatedInformation[] = [];
2151321520
for (const c of candidatesForArgumentError) {
2151421521
const chain = chainDiagnosticMessages(chainDiagnosticMessages(undefined, Diagnostics.Overload_0_gave_the_following_error, signatureToString(c)), Diagnostics.Failed_to_find_a_suitable_overload_for_this_call);
21515-
const [errorNode, msg] = checkApplicableSignature(node, args, c, assignableRelation, CheckMode.Normal, /*reportErrors*/ true, () => chain);
21522+
const r = getSignatureApplicabilityError(node, args, c, assignableRelation, CheckMode.Normal, /*reportErrors*/ true, () => chain);
21523+
if (!r || !r[0]) continue; // TODO:assert!
21524+
diagnostics.add(createDiagnosticForNodeFromMessageChain(r[0], r[1], /*relatedInformation*/ undefined));
2151621525
// related.push(argNode)
2151721526
// This is not right; I want them to be siblings
2151821527
// probably this is a new feature :(
@@ -21552,7 +21561,7 @@ namespace ts {
2155221561
if (typeArguments || !hasCorrectArity(node, args, candidate, signatureHelpTrailingComma)) {
2155321562
return undefined;
2155421563
}
21555-
if (!checkApplicableSignature(node, args, candidate, relation, CheckMode.Normal, /*reportErrors*/ false, /*containingMessageChain*/ undefined)) {
21564+
if (getSignatureApplicabilityError(node, args, candidate, relation, CheckMode.Normal, /*reportErrors*/ false, /*containingMessageChain*/ undefined)) {
2155621565
candidatesForArgumentError = [candidate];
2155721566
return undefined;
2155821567
}
@@ -21593,7 +21602,7 @@ namespace ts {
2159321602
else {
2159421603
checkCandidate = candidate;
2159521604
}
21596-
if (!checkApplicableSignature(node, args, checkCandidate, relation, argCheckMode, /*reportErrors*/ false, /*containingMessageChain*/ undefined)) {
21605+
if (getSignatureApplicabilityError(node, args, checkCandidate, relation, argCheckMode, /*reportErrors*/ false, /*containingMessageChain*/ undefined)) {
2159721606
// Give preference to error candidates that have no rest parameters (as they are more specific)
2159821607
if (getMinArgumentCount(checkCandidate) <= args.length && args.length <= getParameterCount(checkCandidate)) {
2159921608
(candidatesForArgumentError || (candidatesForArgumentError = [])).push(checkCandidate);
@@ -21615,7 +21624,7 @@ namespace ts {
2161521624
continue;
2161621625
}
2161721626
}
21618-
if (!checkApplicableSignature(node, args, checkCandidate, relation, argCheckMode, /*reportErrors*/ false, /*containingMessageChain*/ undefined)) {
21627+
if (getSignatureApplicabilityError(node, args, checkCandidate, relation, argCheckMode, /*reportErrors*/ false, /*containingMessageChain*/ undefined)) {
2161921628
// Give preference to error candidates that have no rest parameters (as they are more specific)
2162021629
if (getMinArgumentCount(checkCandidate) <= args.length && args.length <= getParameterCount(checkCandidate)) {
2162121630
(candidatesForArgumentError || (candidatesForArgumentError = [])).push(checkCandidate);

0 commit comments

Comments
 (0)