Skip to content

Commit c1be793

Browse files
committed
Merge pull request microsoft#255 from Microsoft/forInError
Improve the error in a 'for in' statement
2 parents 34f01f2 + 4ee714f commit c1be793

15 files changed

+21
-21
lines changed

src/compiler/checker.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5213,7 +5213,7 @@ module ts {
52135213
if (node.declaration) {
52145214
checkVariableDeclaration(node.declaration);
52155215
if (node.declaration.type) {
5216-
error(node.declaration, Diagnostics.Variable_declarations_of_a_for_statement_cannot_use_a_type_annotation);
5216+
error(node.declaration, Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_use_a_type_annotation);
52175217
}
52185218
}
52195219

@@ -5224,7 +5224,7 @@ module ts {
52245224
if (node.variable) {
52255225
var exprType = checkExpression(node.variable);
52265226
if (exprType !== anyType && exprType !== stringType) {
5227-
error(node.variable, Diagnostics.Variable_declarations_of_a_for_statement_must_be_of_types_string_or_any);
5227+
error(node.variable, Diagnostics.The_left_hand_side_of_a_for_in_statement_must_be_of_type_string_or_any);
52285228
}
52295229
else {
52305230
// run check only former check succeeded to avoid cascading errors

src/compiler/diagnosticInformationMap.generated.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ module ts {
114114
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." },
115115
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." },
116116
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." },
117-
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." },
118-
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'." },
117+
The_left_hand_side_of_a_for_in_statement_cannot_use_a_type_annotation: { code: 2115, category: DiagnosticCategory.Error, key: "The left-hand side of a 'for...in' statement cannot use a type annotation." },
118+
The_left_hand_side_of_a_for_in_statement_must_be_of_type_string_or_any: { code: 2116, category: DiagnosticCategory.Error, key: "The left-hand side of a 'for...in' statement must be of type 'string' or 'any'." },
119119
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." },
120120
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'." },
121121
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" },

src/compiler/diagnosticMessages.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -448,11 +448,11 @@
448448
"category": "Error",
449449
"code": 2114
450450
},
451-
"Variable declarations of a 'for' statement cannot use a type annotation.": {
451+
"The left-hand side of a 'for...in' statement cannot use a type annotation.": {
452452
"category": "Error",
453453
"code": 2115
454454
},
455-
"Variable declarations of a 'for' statement must be of types 'string' or 'any'.": {
455+
"The left-hand side of a 'for...in' statement must be of type 'string' or 'any'.": {
456456
"category": "Error",
457457
"code": 2116
458458
},

tests/baselines/reference/for-inStatementsInvalid.errors.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22
var aNumber: number;
33
for (aNumber in {}) { }
44
~~~~~~~
5-
!!! Variable declarations of a 'for' statement must be of types 'string' or 'any'.
5+
!!! The left-hand side of a 'for...in' statement must be of type 'string' or 'any'.
66

77
var aBoolean: boolean;
88
for (aBoolean in {}) { }
99
~~~~~~~~
10-
!!! Variable declarations of a 'for' statement must be of types 'string' or 'any'.
10+
!!! The left-hand side of a 'for...in' statement must be of type 'string' or 'any'.
1111

1212
var aRegExp: RegExp;
1313
for (aRegExp in {}) { }
1414
~~~~~~~
15-
!!! Variable declarations of a 'for' statement must be of types 'string' or 'any'.
15+
!!! The left-hand side of a 'for...in' statement must be of type 'string' or 'any'.
1616

1717
for (var idx : number in {}) { }
1818
~~~
19-
!!! Variable declarations of a 'for' statement cannot use a type annotation.
19+
!!! The left-hand side of a 'for...in' statement cannot use a type annotation.
2020

2121
function fn(): void { }
2222
for (var x in fn()) { }

tests/baselines/reference/forIn.errors.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
var arr = null;
33
for (var i:number in arr) { // error
44
~
5-
!!! Variable declarations of a 'for' statement cannot use a type annotation.
5+
!!! The left-hand side of a 'for...in' statement cannot use a type annotation.
66
var x1 = arr[i];
77
var y1 = arr[i];
88
}

tests/baselines/reference/forInStatement4.errors.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
var expr: any;
33
for (var a: number in expr) {
44
~
5-
!!! Variable declarations of a 'for' statement cannot use a type annotation.
5+
!!! The left-hand side of a 'for...in' statement cannot use a type annotation.
66
}

tests/baselines/reference/forInStatement7.errors.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
var expr: any;
44
for (a in expr) {
55
~
6-
!!! Variable declarations of a 'for' statement must be of types 'string' or 'any'.
6+
!!! The left-hand side of a 'for...in' statement must be of type 'string' or 'any'.
77
}

tests/baselines/reference/noImplicitAnyForIn.errors.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@
3939

4040
for (n[idx++] in m);
4141
~~~~~~~~
42-
!!! Variable declarations of a 'for' statement must be of types 'string' or 'any'.
42+
!!! The left-hand side of a 'for...in' statement must be of type 'string' or 'any'.
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
==== tests/cases/conformance/parser/ecmascript5/Statements/parserForInStatement5.ts (2 errors) ====
22
for (var a: number in X) {
33
~
4-
!!! Variable declarations of a 'for' statement cannot use a type annotation.
4+
!!! The left-hand side of a 'for...in' statement cannot use a type annotation.
55
~
66
!!! Cannot find name 'X'.
77
}

tests/baselines/reference/parserForInStatement7.errors.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
~
44
!!! Only a single variable declaration is allowed in a 'for...in' statement.
55
~
6-
!!! Variable declarations of a 'for' statement cannot use a type annotation.
6+
!!! The left-hand side of a 'for...in' statement cannot use a type annotation.
77
~
88
!!! Cannot find name 'X'.
99
}

tests/baselines/reference/parserForStatement3.errors.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
==== tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement3.ts (7 errors) ====
22
for(d in _.jh[a]=_.jh[a]||[],b);
33
~
4-
!!! Variable declarations of a 'for' statement must be of types 'string' or 'any'.
4+
!!! The left-hand side of a 'for...in' statement must be of type 'string' or 'any'.
55
~
66
!!! Cannot find name 'd'.
77
~

tests/baselines/reference/parserForStatement4.errors.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
~
44
!!! Cannot find name 'a'.
55
~~~~~
6-
!!! Variable declarations of a 'for' statement must be of types 'string' or 'any'.
6+
!!! The left-hand side of a 'for...in' statement must be of type 'string' or 'any'.
77
~
88
!!! Cannot find name 'b'.
99
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
==== tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement5.ts (2 errors) ====
22
for ({} in b) {
33
~~
4-
!!! Variable declarations of a 'for' statement must be of types 'string' or 'any'.
4+
!!! The left-hand side of a 'for...in' statement must be of type 'string' or 'any'.
55
~
66
!!! Cannot find name 'b'.
77
}

tests/baselines/reference/parserForStatement6.errors.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
~~~
44
!!! Cannot find name 'foo'.
55
~~~~~
6-
!!! Variable declarations of a 'for' statement must be of types 'string' or 'any'.
6+
!!! The left-hand side of a 'for...in' statement must be of type 'string' or 'any'.
77
~
88
!!! Cannot find name 'b'.
99
}

tests/baselines/reference/parserForStatement7.errors.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
==== tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement7.ts (3 errors) ====
22
for (new foo() in b) {
33
~~~~~~~~~
4-
!!! Variable declarations of a 'for' statement must be of types 'string' or 'any'.
4+
!!! The left-hand side of a 'for...in' statement must be of type 'string' or 'any'.
55
~~~
66
!!! Cannot find name 'foo'.
77
~

0 commit comments

Comments
 (0)