Add tests for circular references in for...of loops

This commit is contained in:
Jason Freeman 2015-02-24 17:26:16 -08:00
parent 0049b21d6c
commit 034bd09526
13 changed files with 181 additions and 14 deletions

View File

@ -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 {

View 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.

View File

@ -0,0 +1,5 @@
//// [for-of32.ts]
for (var v of v) { }
//// [for-of32.js]
for (var v of v) { }

View 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;
}
}

View 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;
})();

View 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;
}
}

View 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;
})();

View 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;
}
}

View 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;
})();

View File

@ -0,0 +1,3 @@
//@target: ES6
//@noImplicitAny: true
for (var v of v) { }

View File

@ -0,0 +1,9 @@
//@target: ES6
//@noImplicitAny: true
for (var v of new StringIterator) { }
class StringIterator {
[Symbol.iterator]() {
return v;
}
}

View File

@ -0,0 +1,13 @@
//@target: ES6
//@noImplicitAny: true
for (var v of new StringIterator) { }
class StringIterator {
next() {
return v;
}
[Symbol.iterator]() {
return this;
}
}

View 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;
}
}