do not report cascading errors in instanceof operator
This commit is contained in:
parent
8be8e1f5be
commit
649f5c01a4
|
@ -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;
|
||||
|
|
|
@ -68,8 +68,6 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(40,28): error TS
|
|||
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(41,21): error TS2304: Cannot find name 'retValue'.
|
||||
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(47,17): error TS2304: Cannot find name 'console'.
|
||||
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(53,13): error TS2304: Cannot find name 'console'.
|
||||
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(76,26): error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter.
|
||||
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(76,44): error TS2359: The right-hand side of an 'instanceof' expression must be of type 'any' or of a type assignable to the 'Function' interface type.
|
||||
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(89,23): error TS2364: Invalid left-hand side of assignment expression.
|
||||
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(108,24): error TS2365: Operator '+' cannot be applied to types 'number' and 'boolean'.
|
||||
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(159,31): error TS2304: Cannot find name 'Property'.
|
||||
|
@ -98,7 +96,7 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,29): error T
|
|||
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,37): error TS2304: Cannot find name 'string'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts (98 errors) ====
|
||||
==== tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts (96 errors) ====
|
||||
declare module "fs" {
|
||||
export class File {
|
||||
constructor(filename: string);
|
||||
|
@ -242,10 +240,6 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,37): error T
|
|||
|
||||
var local5 = <fs.File>null;
|
||||
var local6 = local5 instanceof fs.File;
|
||||
~~~~~~
|
||||
!!! error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter.
|
||||
~~~~~~~
|
||||
!!! error TS2359: The right-hand side of an 'instanceof' expression must be of type 'any' or of a type assignable to the 'Function' interface type.
|
||||
|
||||
var hex = 0xBADC0DE, Hex = 0XDEADBEEF;
|
||||
var float = 6.02e23, float2 = 6.02E-23
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
tests/cases/compiler/errorHandlingInInstanceOf.ts(1,5): error TS2304: Cannot find name 'x'.
|
||||
tests/cases/compiler/errorHandlingInInstanceOf.ts(5,18): error TS2304: Cannot find name 'UnknownType'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/errorHandlingInInstanceOf.ts (2 errors) ====
|
||||
if (x instanceof String) {
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'x'.
|
||||
}
|
||||
|
||||
var y: any;
|
||||
if (y instanceof UnknownType) {
|
||||
~~~~~~~~~~~
|
||||
!!! error TS2304: Cannot find name 'UnknownType'.
|
||||
}
|
14
tests/baselines/reference/errorHandlingInInstanceOf.js
Normal file
14
tests/baselines/reference/errorHandlingInInstanceOf.js
Normal file
|
@ -0,0 +1,14 @@
|
|||
//// [errorHandlingInInstanceOf.ts]
|
||||
if (x instanceof String) {
|
||||
}
|
||||
|
||||
var y: any;
|
||||
if (y instanceof UnknownType) {
|
||||
}
|
||||
|
||||
//// [errorHandlingInInstanceOf.js]
|
||||
if (x instanceof String) {
|
||||
}
|
||||
var y;
|
||||
if (y instanceof UnknownType) {
|
||||
}
|
6
tests/cases/compiler/errorHandlingInInstanceOf.ts
Normal file
6
tests/cases/compiler/errorHandlingInInstanceOf.ts
Normal file
|
@ -0,0 +1,6 @@
|
|||
if (x instanceof String) {
|
||||
}
|
||||
|
||||
var y: any;
|
||||
if (y instanceof UnknownType) {
|
||||
}
|
Loading…
Reference in a new issue