Improve the error in a 'for in' statement
This commit is contained in:
parent
2843b82f08
commit
b2abab2f93
|
@ -5214,7 +5214,7 @@ module ts {
|
|||
if (node.declaration) {
|
||||
checkVariableDeclaration(node.declaration);
|
||||
if (node.declaration.type) {
|
||||
error(node.declaration, Diagnostics.Variable_declarations_of_a_for_statement_cannot_use_a_type_annotation);
|
||||
error(node.declaration, Diagnostics.Left_hand_side_of_a_for_statement_cannot_use_a_type_annotation);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5225,7 +5225,7 @@ module ts {
|
|||
if (node.variable) {
|
||||
var exprType = checkExpression(node.variable);
|
||||
if (exprType !== anyType && exprType !== stringType) {
|
||||
error(node.variable, Diagnostics.Variable_declarations_of_a_for_statement_must_be_of_types_string_or_any);
|
||||
error(node.variable, Diagnostics.Left_hand_side_of_a_for_statement_must_be_of_type_string_or_any);
|
||||
}
|
||||
else {
|
||||
// run check only former check succeeded to avoid cascading errors
|
||||
|
|
|
@ -114,8 +114,8 @@ module ts {
|
|||
The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type: { code: 2112, category: DiagnosticCategory.Error, key: "The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type." },
|
||||
The_left_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type: { code: 2113, category: DiagnosticCategory.Error, key: "The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type." },
|
||||
An_arithmetic_operand_must_be_of_type_any_number_or_an_enum_type: { code: 2114, category: DiagnosticCategory.Error, key: "An arithmetic operand must be of type 'any', 'number' or an enum type." },
|
||||
Variable_declarations_of_a_for_statement_cannot_use_a_type_annotation: { code: 2115, category: DiagnosticCategory.Error, key: "Variable declarations of a 'for' statement cannot use a type annotation." },
|
||||
Variable_declarations_of_a_for_statement_must_be_of_types_string_or_any: { code: 2116, category: DiagnosticCategory.Error, key: "Variable declarations of a 'for' statement must be of types 'string' or 'any'." },
|
||||
Left_hand_side_of_a_for_statement_cannot_use_a_type_annotation: { code: 2115, category: DiagnosticCategory.Error, key: "Left hand side of a 'for' statement cannot use a type annotation." },
|
||||
Left_hand_side_of_a_for_statement_must_be_of_type_string_or_any: { code: 2116, category: DiagnosticCategory.Error, key: "Left hand side of a 'for' statement must be of type 'string' or 'any'." },
|
||||
The_right_hand_side_of_a_for_in_statement_must_be_of_type_any_an_object_type_or_a_type_parameter: { code: 2117, category: DiagnosticCategory.Error, key: "The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter." },
|
||||
The_left_hand_side_of_an_in_expression_must_be_of_types_any_string_or_number: { code: 2118, category: DiagnosticCategory.Error, key: "The left-hand side of an 'in' expression must be of types 'any', 'string' or 'number'." },
|
||||
The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter: { code: 2119, category: DiagnosticCategory.Error, key: "The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter" },
|
||||
|
|
|
@ -448,11 +448,11 @@
|
|||
"category": "Error",
|
||||
"code": 2114
|
||||
},
|
||||
"Variable declarations of a 'for' statement cannot use a type annotation.": {
|
||||
"Left hand side of a 'for' statement cannot use a type annotation.": {
|
||||
"category": "Error",
|
||||
"code": 2115
|
||||
},
|
||||
"Variable declarations of a 'for' statement must be of types 'string' or 'any'.": {
|
||||
"Left hand side of a 'for' statement must be of type 'string' or 'any'.": {
|
||||
"category": "Error",
|
||||
"code": 2116
|
||||
},
|
||||
|
|
|
@ -2,21 +2,21 @@
|
|||
var aNumber: number;
|
||||
for (aNumber in {}) { }
|
||||
~~~~~~~
|
||||
!!! Variable declarations of a 'for' statement must be of types 'string' or 'any'.
|
||||
!!! Left hand side of a 'for' statement must be of type 'string' or 'any'.
|
||||
|
||||
var aBoolean: boolean;
|
||||
for (aBoolean in {}) { }
|
||||
~~~~~~~~
|
||||
!!! Variable declarations of a 'for' statement must be of types 'string' or 'any'.
|
||||
!!! Left hand side of a 'for' statement must be of type 'string' or 'any'.
|
||||
|
||||
var aRegExp: RegExp;
|
||||
for (aRegExp in {}) { }
|
||||
~~~~~~~
|
||||
!!! Variable declarations of a 'for' statement must be of types 'string' or 'any'.
|
||||
!!! Left hand side of a 'for' statement must be of type 'string' or 'any'.
|
||||
|
||||
for (var idx : number in {}) { }
|
||||
~~~
|
||||
!!! Variable declarations of a 'for' statement cannot use a type annotation.
|
||||
!!! Left hand side of a 'for' statement cannot use a type annotation.
|
||||
|
||||
function fn(): void { }
|
||||
for (var x in fn()) { }
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
var arr = null;
|
||||
for (var i:number in arr) { // error
|
||||
~
|
||||
!!! Variable declarations of a 'for' statement cannot use a type annotation.
|
||||
!!! Left hand side of a 'for' statement cannot use a type annotation.
|
||||
var x1 = arr[i];
|
||||
var y1 = arr[i];
|
||||
}
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
var expr: any;
|
||||
for (var a: number in expr) {
|
||||
~
|
||||
!!! Variable declarations of a 'for' statement cannot use a type annotation.
|
||||
!!! Left hand side of a 'for' statement cannot use a type annotation.
|
||||
}
|
|
@ -3,5 +3,5 @@
|
|||
var expr: any;
|
||||
for (a in expr) {
|
||||
~
|
||||
!!! Variable declarations of a 'for' statement must be of types 'string' or 'any'.
|
||||
!!! Left hand side of a 'for' statement must be of type 'string' or 'any'.
|
||||
}
|
|
@ -39,4 +39,4 @@
|
|||
|
||||
for (n[idx++] in m);
|
||||
~~~~~~~~
|
||||
!!! Variable declarations of a 'for' statement must be of types 'string' or 'any'.
|
||||
!!! Left hand side of a 'for' statement must be of type 'string' or 'any'.
|
|
@ -1,7 +1,7 @@
|
|||
==== tests/cases/conformance/parser/ecmascript5/Statements/parserForInStatement5.ts (2 errors) ====
|
||||
for (var a: number in X) {
|
||||
~
|
||||
!!! Variable declarations of a 'for' statement cannot use a type annotation.
|
||||
!!! Left hand side of a 'for' statement cannot use a type annotation.
|
||||
~
|
||||
!!! Cannot find name 'X'.
|
||||
}
|
|
@ -3,7 +3,7 @@
|
|||
~
|
||||
!!! Only a single variable declaration is allowed in a 'for...in' statement.
|
||||
~
|
||||
!!! Variable declarations of a 'for' statement cannot use a type annotation.
|
||||
!!! Left hand side of a 'for' statement cannot use a type annotation.
|
||||
~
|
||||
!!! Cannot find name 'X'.
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
==== tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement3.ts (7 errors) ====
|
||||
for(d in _.jh[a]=_.jh[a]||[],b);
|
||||
~
|
||||
!!! Variable declarations of a 'for' statement must be of types 'string' or 'any'.
|
||||
!!! Left hand side of a 'for' statement must be of type 'string' or 'any'.
|
||||
~
|
||||
!!! Cannot find name 'd'.
|
||||
~
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
~
|
||||
!!! Cannot find name 'a'.
|
||||
~~~~~
|
||||
!!! Variable declarations of a 'for' statement must be of types 'string' or 'any'.
|
||||
!!! Left hand side of a 'for' statement must be of type 'string' or 'any'.
|
||||
~
|
||||
!!! Cannot find name 'b'.
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
==== tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement5.ts (2 errors) ====
|
||||
for ({} in b) {
|
||||
~~
|
||||
!!! Variable declarations of a 'for' statement must be of types 'string' or 'any'.
|
||||
!!! Left hand side of a 'for' statement must be of type 'string' or 'any'.
|
||||
~
|
||||
!!! Cannot find name 'b'.
|
||||
}
|
|
@ -3,7 +3,7 @@
|
|||
~~~
|
||||
!!! Cannot find name 'foo'.
|
||||
~~~~~
|
||||
!!! Variable declarations of a 'for' statement must be of types 'string' or 'any'.
|
||||
!!! Left hand side of a 'for' statement must be of type 'string' or 'any'.
|
||||
~
|
||||
!!! Cannot find name 'b'.
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
==== tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement7.ts (3 errors) ====
|
||||
for (new foo() in b) {
|
||||
~~~~~~~~~
|
||||
!!! Variable declarations of a 'for' statement must be of types 'string' or 'any'.
|
||||
!!! Left hand side of a 'for' statement must be of type 'string' or 'any'.
|
||||
~~~
|
||||
!!! Cannot find name 'foo'.
|
||||
~
|
||||
|
|
Loading…
Reference in a new issue