do not report cascading errors in instanceof operator

This commit is contained in:
Vladimir Matveev
2014-09-24 09:10:40 -07:00
parent 8be8e1f5be
commit 649f5c01a4
5 changed files with 40 additions and 9 deletions

View File

@@ -4935,10 +4935,12 @@ module ts {
// The instanceof operator requires the left operand to be of type Any, an object type, or a type parameter type,
// and the right operand to be of type Any or a subtype of the 'Function' interface type.
// The result is always of the Boolean primitive type.
if (!isTypeAnyTypeObjectTypeOrTypeParameter(leftType)) {
// NOTE: do not raise error is leftType is unknown as related error was already reported
if (leftType !== unknownType && !isTypeAnyTypeObjectTypeOrTypeParameter(leftType)) {
error(node.left, Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter);
}
if (rightType !== anyType && !isTypeSubtypeOf(rightType, globalFunctionType)) {
// NOTE: do not raise error is right is unknown as related error was already reported
if (rightType !== unknownType && rightType !== anyType && !isTypeSubtypeOf(rightType, globalFunctionType)) {
error(node.right, Diagnostics.The_right_hand_side_of_an_instanceof_expression_must_be_of_type_any_or_of_a_type_assignable_to_the_Function_interface_type);
}
return booleanType;