Clean up original errors

The old "supplied parameters do not match any call signature" was
either inaccurate, redundant or vague. The previous commits fix the
vagueness problem. This commit fixes the inaccuracy and redundancy.

1. When there are NO candidates, the error should say so. (This only
happens once in our tests, when calling `super()` with a base class of
type `any` in a JS file.)
2. When the call is to a decorator, `resolveCall` already receives a
specific fallback error message from the decorator handling code. Adding
"supplied parameters do not match ..." is not helpful.

I also cleaned up the new code a bit after I noticed that all the error
creation functions take `string | number`, so I didn't need calls to
`toString` in my code.
This commit is contained in:
Nathan Shively-Sanders
2017-05-16 09:48:23 -07:00
parent ca61755eb5
commit 353d9e2310
2 changed files with 11 additions and 22 deletions

View File

@@ -15208,7 +15208,7 @@ namespace ts {
}
}
function resolveCall(node: CallLikeExpression, signatures: Signature[], candidatesOutArray: Signature[], headMessage?: DiagnosticMessage): Signature {
function resolveCall(node: CallLikeExpression, signatures: Signature[], candidatesOutArray: Signature[], fallbackError?: DiagnosticMessage): Signature {
const isTaggedTemplate = node.kind === SyntaxKind.TaggedTemplateExpression;
const isDecorator = node.kind === SyntaxKind.Decorator;
const isJsxOpeningOrSelfClosingElement = isJsxOpeningLikeElement(node);
@@ -15243,7 +15243,7 @@ namespace ts {
// reorderCandidates fills up the candidates array directly
reorderCandidates(signatures, candidates);
if (!candidates.length) {
reportError(Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target);
diagnostics.add(createDiagnosticForNode(node, Diagnostics.Call_target_does_not_contain_any_signatures));
return resolveErrorCall(node);
}
@@ -15351,7 +15351,7 @@ namespace ts {
else if (candidateForTypeArgumentError) {
if (!isTaggedTemplate && !isDecorator && typeArguments) {
const typeArguments = (<CallExpression>node).typeArguments;
checkTypeArguments(candidateForTypeArgumentError, typeArguments, map(typeArguments, getTypeFromTypeNode), /*reportErrors*/ true, headMessage);
checkTypeArguments(candidateForTypeArgumentError, typeArguments, map(typeArguments, getTypeFromTypeNode), /*reportErrors*/ true, fallbackError);
}
else {
Debug.assert(resultOfFailedInference.failedTypeParameterIndex >= 0);
@@ -15362,8 +15362,8 @@ namespace ts {
Diagnostics.The_type_argument_for_type_parameter_0_cannot_be_inferred_from_the_usage_Consider_specifying_the_type_arguments_explicitly,
typeToString(failedTypeParameter));
if (headMessage) {
diagnosticChainHead = chainDiagnosticMessages(diagnosticChainHead, headMessage);
if (fallbackError) {
diagnosticChainHead = chainDiagnosticMessages(diagnosticChainHead, fallbackError);
}
reportNoCommonSupertypeError(inferenceCandidates, (<JsxOpeningLikeElement>node).tagName || (<CallExpression>node).expression || (<TaggedTemplateExpression>node).tag, diagnosticChainHead);
@@ -15376,8 +15376,8 @@ namespace ts {
min = Math.min(min, getMinTypeArgumentCount(sig.typeParameters));
max = Math.max(max, length(sig.typeParameters));
}
const paramMessage = max > min ? `${min}-${max}` : min.toString();
reportError(Diagnostics.Expected_0_type_arguments_but_got_1, paramMessage, typeArguments.length.toString());
const paramCount = min < max ? `${min}-${max}` : min;
diagnostics.add(createDiagnosticForNode(node, Diagnostics.Expected_0_type_arguments_but_got_1, paramCount, typeArguments.length));
}
else if (args) {
let min = Number.POSITIVE_INFINITY;
@@ -15386,7 +15386,6 @@ namespace ts {
min = Math.min(min, sig.minArgumentCount);
max = Math.max(max, sig.parameters.length);
}
///////////
const hasRestParameter = some(signatures, sig => sig.hasRestParameter);
const hasSpreadArgument = getSpreadArgumentIndex(args) > -1;
const paramCount = hasRestParameter ? min :
@@ -15397,10 +15396,10 @@ namespace ts {
hasRestParameter ? Diagnostics.Expected_at_least_0_arguments_but_got_1 :
hasSpreadArgument ? Diagnostics.Expected_0_arguments_but_got_a_minimum_of_1 :
Diagnostics.Expected_0_arguments_but_got_1;
reportError(error, paramCount.toString(), argCount.toString());
diagnostics.add(createDiagnosticForNode(node, error, paramCount, argCount));
}
else {
reportError(Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target);
else if (fallbackError) {
diagnostics.add(createDiagnosticForNode(node, fallbackError));
}
// No signature was applicable. We have already reported the errors for the invalid signature.
@@ -15421,16 +15420,6 @@ namespace ts {
return resolveErrorCall(node);
function reportError(message: DiagnosticMessage, arg0?: string, arg1?: string, arg2?: string): void {
let errorInfo: DiagnosticMessageChain;
errorInfo = chainDiagnosticMessages(errorInfo, message, arg0, arg1, arg2);
if (headMessage) {
errorInfo = chainDiagnosticMessages(errorInfo, headMessage);
}
diagnostics.add(createDiagnosticForNodeFromMessageChain(node, errorInfo));
}
function chooseOverload(candidates: Signature[], relation: Map<RelationComparisonResult>, signatureHelpTrailingComma = false) {
for (const originalCandidate of candidates) {
if (!hasCorrectArity(node, args, originalCandidate, signatureHelpTrailingComma)) {

View File

@@ -1067,7 +1067,7 @@
"category": "Error",
"code": 2345
},
"Supplied parameters do not match any signature of call target.": {
"Call target does not contain any signatures.": {
"category": "Error",
"code": 2346
},