mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-09 20:51:43 -06:00
Add tests for circular references in for...of loops
This commit is contained in:
parent
0049b21d6c
commit
034bd09526
@ -8828,20 +8828,7 @@ module ts {
|
||||
return anyType;
|
||||
}
|
||||
|
||||
var variable = forOfStatement.initializer;
|
||||
var links = getNodeLinks(variable);
|
||||
if (!links.resolvedType) {
|
||||
links.resolvedType = resolvingType;
|
||||
var type = getIteratedType(getTypeOfExpression(forOfStatement.expression), forOfStatement.expression);
|
||||
if (links.resolvedType === resolvingType) {
|
||||
links.resolvedType = type;
|
||||
}
|
||||
}
|
||||
else if (links.resolvedType === resolvingType) {
|
||||
links.resolvedType = anyType;
|
||||
}
|
||||
|
||||
return links.resolvedType;
|
||||
return getIteratedType(getTypeOfExpression(forOfStatement.expression), forOfStatement.expression);
|
||||
}
|
||||
|
||||
function getIteratedType(iterable: Type, expressionForError: Expression): Type {
|
||||
|
||||
7
tests/baselines/reference/for-of32.errors.txt
Normal file
7
tests/baselines/reference/for-of32.errors.txt
Normal file
@ -0,0 +1,7 @@
|
||||
tests/cases/conformance/es6/for-ofStatements/for-of32.ts(1,10): error TS7022: 'v' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/for-ofStatements/for-of32.ts (1 errors) ====
|
||||
for (var v of v) { }
|
||||
~
|
||||
!!! error TS7022: 'v' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer.
|
||||
5
tests/baselines/reference/for-of32.js
Normal file
5
tests/baselines/reference/for-of32.js
Normal file
@ -0,0 +1,5 @@
|
||||
//// [for-of32.ts]
|
||||
for (var v of v) { }
|
||||
|
||||
//// [for-of32.js]
|
||||
for (var v of v) { }
|
||||
13
tests/baselines/reference/for-of33.errors.txt
Normal file
13
tests/baselines/reference/for-of33.errors.txt
Normal file
@ -0,0 +1,13 @@
|
||||
tests/cases/conformance/es6/for-ofStatements/for-of33.ts(1,10): error TS7022: 'v' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/for-ofStatements/for-of33.ts (1 errors) ====
|
||||
for (var v of new StringIterator) { }
|
||||
~
|
||||
!!! error TS7022: 'v' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer.
|
||||
|
||||
class StringIterator {
|
||||
[Symbol.iterator]() {
|
||||
return v;
|
||||
}
|
||||
}
|
||||
19
tests/baselines/reference/for-of33.js
Normal file
19
tests/baselines/reference/for-of33.js
Normal file
@ -0,0 +1,19 @@
|
||||
//// [for-of33.ts]
|
||||
for (var v of new StringIterator) { }
|
||||
|
||||
class StringIterator {
|
||||
[Symbol.iterator]() {
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
//// [for-of33.js]
|
||||
for (var v of new StringIterator) { }
|
||||
var StringIterator = (function () {
|
||||
function StringIterator() {
|
||||
}
|
||||
StringIterator.prototype[Symbol.iterator] = function () {
|
||||
return v;
|
||||
};
|
||||
return StringIterator;
|
||||
})();
|
||||
17
tests/baselines/reference/for-of34.errors.txt
Normal file
17
tests/baselines/reference/for-of34.errors.txt
Normal file
@ -0,0 +1,17 @@
|
||||
tests/cases/conformance/es6/for-ofStatements/for-of34.ts(1,10): error TS7022: 'v' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/for-ofStatements/for-of34.ts (1 errors) ====
|
||||
for (var v of new StringIterator) { }
|
||||
~
|
||||
!!! error TS7022: 'v' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer.
|
||||
|
||||
class StringIterator {
|
||||
next() {
|
||||
return v;
|
||||
}
|
||||
|
||||
[Symbol.iterator]() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
26
tests/baselines/reference/for-of34.js
Normal file
26
tests/baselines/reference/for-of34.js
Normal file
@ -0,0 +1,26 @@
|
||||
//// [for-of34.ts]
|
||||
for (var v of new StringIterator) { }
|
||||
|
||||
class StringIterator {
|
||||
next() {
|
||||
return v;
|
||||
}
|
||||
|
||||
[Symbol.iterator]() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
//// [for-of34.js]
|
||||
for (var v of new StringIterator) { }
|
||||
var StringIterator = (function () {
|
||||
function StringIterator() {
|
||||
}
|
||||
StringIterator.prototype.next = function () {
|
||||
return v;
|
||||
};
|
||||
StringIterator.prototype[Symbol.iterator] = function () {
|
||||
return this;
|
||||
};
|
||||
return StringIterator;
|
||||
})();
|
||||
20
tests/baselines/reference/for-of35.errors.txt
Normal file
20
tests/baselines/reference/for-of35.errors.txt
Normal file
@ -0,0 +1,20 @@
|
||||
tests/cases/conformance/es6/for-ofStatements/for-of35.ts(1,10): error TS7022: 'v' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/for-ofStatements/for-of35.ts (1 errors) ====
|
||||
for (var v of new StringIterator) { }
|
||||
~
|
||||
!!! error TS7022: 'v' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer.
|
||||
|
||||
class StringIterator {
|
||||
next() {
|
||||
return {
|
||||
done: true,
|
||||
value: v
|
||||
}
|
||||
}
|
||||
|
||||
[Symbol.iterator]() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
32
tests/baselines/reference/for-of35.js
Normal file
32
tests/baselines/reference/for-of35.js
Normal file
@ -0,0 +1,32 @@
|
||||
//// [for-of35.ts]
|
||||
for (var v of new StringIterator) { }
|
||||
|
||||
class StringIterator {
|
||||
next() {
|
||||
return {
|
||||
done: true,
|
||||
value: v
|
||||
}
|
||||
}
|
||||
|
||||
[Symbol.iterator]() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
//// [for-of35.js]
|
||||
for (var v of new StringIterator) { }
|
||||
var StringIterator = (function () {
|
||||
function StringIterator() {
|
||||
}
|
||||
StringIterator.prototype.next = function () {
|
||||
return {
|
||||
done: true,
|
||||
value: v
|
||||
};
|
||||
};
|
||||
StringIterator.prototype[Symbol.iterator] = function () {
|
||||
return this;
|
||||
};
|
||||
return StringIterator;
|
||||
})();
|
||||
3
tests/cases/conformance/es6/for-ofStatements/for-of32.ts
Normal file
3
tests/cases/conformance/es6/for-ofStatements/for-of32.ts
Normal file
@ -0,0 +1,3 @@
|
||||
//@target: ES6
|
||||
//@noImplicitAny: true
|
||||
for (var v of v) { }
|
||||
9
tests/cases/conformance/es6/for-ofStatements/for-of33.ts
Normal file
9
tests/cases/conformance/es6/for-ofStatements/for-of33.ts
Normal file
@ -0,0 +1,9 @@
|
||||
//@target: ES6
|
||||
//@noImplicitAny: true
|
||||
for (var v of new StringIterator) { }
|
||||
|
||||
class StringIterator {
|
||||
[Symbol.iterator]() {
|
||||
return v;
|
||||
}
|
||||
}
|
||||
13
tests/cases/conformance/es6/for-ofStatements/for-of34.ts
Normal file
13
tests/cases/conformance/es6/for-ofStatements/for-of34.ts
Normal file
@ -0,0 +1,13 @@
|
||||
//@target: ES6
|
||||
//@noImplicitAny: true
|
||||
for (var v of new StringIterator) { }
|
||||
|
||||
class StringIterator {
|
||||
next() {
|
||||
return v;
|
||||
}
|
||||
|
||||
[Symbol.iterator]() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
16
tests/cases/conformance/es6/for-ofStatements/for-of35.ts
Normal file
16
tests/cases/conformance/es6/for-ofStatements/for-of35.ts
Normal file
@ -0,0 +1,16 @@
|
||||
//@target: ES6
|
||||
//@noImplicitAny: true
|
||||
for (var v of new StringIterator) { }
|
||||
|
||||
class StringIterator {
|
||||
next() {
|
||||
return {
|
||||
done: true,
|
||||
value: v
|
||||
}
|
||||
}
|
||||
|
||||
[Symbol.iterator]() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user