Use a more direct error.

This commit is contained in:
Daniel Rosenwasser
2018-06-28 16:06:55 -07:00
parent 2a19580144
commit 6f06fd0d46
3 changed files with 20 additions and 21 deletions
+16 -17
View File
@@ -20904,31 +20904,30 @@ namespace ts {
}
function reportOperatorError() {
let err = chainDiagnosticMessages(
/*elaboration*/ undefined,
Diagnostics.Operator_0_cannot_be_applied_to_types_1_and_2,
tokenToString(operatorToken.kind),
typeToString(leftType),
typeToString(rightType)
);
err = giveBetterPrimaryError(err);
diagnostics.add(createDiagnosticForNodeFromMessageChain(
errorNode || operatorToken,
err
));
const leftStr = typeToString(leftType);
const rightStr = typeToString(rightType);
const errNode = errorNode || operatorToken;
if (!tryGiveBetterPrimaryError(errNode, leftStr, rightStr)) {
error(
errNode,
Diagnostics.Operator_0_cannot_be_applied_to_types_1_and_2,
tokenToString(operatorToken.kind),
leftStr,
rightStr,
);
}
}
function giveBetterPrimaryError(elaboration: DiagnosticMessageChain) {
function tryGiveBetterPrimaryError(errNode: Node, leftStr: string, rightStr: string) {
switch (operatorToken.kind) {
case SyntaxKind.EqualsEqualsEqualsToken:
case SyntaxKind.EqualsEqualsToken:
return chainDiagnosticMessages(elaboration, Diagnostics.The_types_of_these_values_indicate_that_this_condition_will_always_be_0, "false");
return error(errNode, Diagnostics.This_condition_will_always_return_0_since_the_types_1_and_2_have_no_overlap, "false", leftStr, rightStr);
case SyntaxKind.ExclamationEqualsEqualsToken:
case SyntaxKind.ExclamationEqualsToken:
return chainDiagnosticMessages(elaboration, Diagnostics.The_types_of_these_values_indicate_that_this_condition_will_always_be_0, "true");
return error(errNode, Diagnostics.This_condition_will_always_return_0_since_the_types_1_and_2_have_no_overlap, "true", leftStr, rightStr);
}
return elaboration;
return undefined;
}
}
+1 -1
View File
@@ -1252,7 +1252,7 @@
"category": "Error",
"code": 2366
},
"The types of these values indicate that this condition will always be '{0}'.": {
"This condition will always return '{0}' since the types '{1}' and '{2}' have no overlap.": {
"category": "Error",
"code": 2367
},
@@ -5016,7 +5016,7 @@ namespace ts.projectSystem {
);
const errorResult = <protocol.Diagnostic[]>session.executeCommand(getErrRequest).response;
assert.isTrue(errorResult.length === 1);
assert.equal(errorResult[0].code, Diagnostics.The_types_of_these_values_indicate_that_this_condition_will_always_be_0.code);
assert.equal(errorResult[0].code, Diagnostics.This_condition_will_always_return_0_since_the_types_1_and_2_have_no_overlap.code);
});
it("should report semantic errors for configured js project with '// @ts-check' and skipLibCheck=true", () => {
@@ -5043,7 +5043,7 @@ namespace ts.projectSystem {
);
const errorResult = <protocol.Diagnostic[]>session.executeCommand(getErrRequest).response;
assert.isTrue(errorResult.length === 1);
assert.equal(errorResult[0].code, Diagnostics.The_types_of_these_values_indicate_that_this_condition_will_always_be_0.code);
assert.equal(errorResult[0].code, Diagnostics.This_condition_will_always_return_0_since_the_types_1_and_2_have_no_overlap.code);
});
it("should report semantic errors for configured js project with checkJs=true and skipLibCheck=true", () => {
@@ -5072,7 +5072,7 @@ namespace ts.projectSystem {
);
const errorResult = <protocol.Diagnostic[]>session.executeCommand(getErrRequest).response;
assert.isTrue(errorResult.length === 1);
assert.equal(errorResult[0].code, Diagnostics.The_types_of_these_values_indicate_that_this_condition_will_always_be_0.code);
assert.equal(errorResult[0].code, Diagnostics.This_condition_will_always_return_0_since_the_types_1_and_2_have_no_overlap.code);
});
});