Merge pull request #737 from Microsoft/instanceof_cascading_errors

do not report cascading errors in instanceof operator
This commit is contained in:
Vladimir Matveev
2014-09-24 11:09:21 -07:00
5 changed files with 40 additions and 9 deletions

View File

@@ -4984,10 +4984,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 if 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 if 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;