Skip to content
Closed
628 changes: 351 additions & 277 deletions src/compiler/checker.ts

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5277,6 +5277,7 @@ namespace ts {
iterationTypesOfGeneratorReturnType?: IterationTypes;
iterationTypesOfAsyncGeneratorReturnType?: IterationTypes;
iterationTypesOfIterable?: IterationTypes;
iterationTypesOfAsyncedSyncIterable?: IterationTypes;
iterationTypesOfIterator?: IterationTypes;
iterationTypesOfAsyncIterable?: IterationTypes;
iterationTypesOfAsyncIterator?: IterationTypes;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
tests/cases/compiler/cachedIterableTypesShouldAlwaysError.ts(5,18): error TS2488: Type '{ x: "x"; [Symbol.iterator](): Generator<{ b: false; }, any, unknown>; } | { y: "y"; }' must have a '[Symbol.iterator]()' method that returns an iterator.
tests/cases/compiler/cachedIterableTypesShouldAlwaysError.ts(9,18): error TS2488: Type '{ x: "x"; [Symbol.iterator](): Generator<{ b: false; }, any, unknown>; } | { y: "y"; }' must have a '[Symbol.iterator]()' method that returns an iterator.


==== tests/cases/compiler/cachedIterableTypesShouldAlwaysError.ts (2 errors) ====
function foo(obj:
{ x: "x", [Symbol.iterator](): Generator<{ b: false }> } |
{ y: "y" }
) {
for (const k of obj) { // should error
~~~
!!! error TS2488: Type '{ x: "x"; [Symbol.iterator](): Generator<{ b: false; }, any, unknown>; } | { y: "y"; }' must have a '[Symbol.iterator]()' method that returns an iterator.
void k;
}

for (const k of obj) { // should error
~~~
!!! error TS2488: Type '{ x: "x"; [Symbol.iterator](): Generator<{ b: false; }, any, unknown>; } | { y: "y"; }' must have a '[Symbol.iterator]()' method that returns an iterator.
void k;
}
}

24 changes: 24 additions & 0 deletions tests/baselines/reference/cachedIterableTypesShouldAlwaysError.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//// [cachedIterableTypesShouldAlwaysError.ts]
function foo(obj:
{ x: "x", [Symbol.iterator](): Generator<{ b: false }> } |
{ y: "y" }
) {
for (const k of obj) { // should error
void k;
}

for (const k of obj) { // should error
void k;
}
}


//// [cachedIterableTypesShouldAlwaysError.js]
function foo(obj) {
for (const k of obj) { // should error
void k;
}
for (const k of obj) { // should error
void k;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
=== tests/cases/compiler/cachedIterableTypesShouldAlwaysError.ts ===
function foo(obj:
>foo : Symbol(foo, Decl(cachedIterableTypesShouldAlwaysError.ts, 0, 0))
>obj : Symbol(obj, Decl(cachedIterableTypesShouldAlwaysError.ts, 0, 13))

{ x: "x", [Symbol.iterator](): Generator<{ b: false }> } |
>x : Symbol(x, Decl(cachedIterableTypesShouldAlwaysError.ts, 1, 5))
>[Symbol.iterator] : Symbol([Symbol.iterator], Decl(cachedIterableTypesShouldAlwaysError.ts, 1, 13))
>Symbol.iterator : Symbol(SymbolConstructor.iterator, Decl(lib.es2015.iterable.d.ts, --, --))
>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
>iterator : Symbol(SymbolConstructor.iterator, Decl(lib.es2015.iterable.d.ts, --, --))
>Generator : Symbol(Generator, Decl(lib.es2015.generator.d.ts, --, --))
>b : Symbol(b, Decl(cachedIterableTypesShouldAlwaysError.ts, 1, 46))

{ y: "y" }
>y : Symbol(y, Decl(cachedIterableTypesShouldAlwaysError.ts, 2, 5))

) {
for (const k of obj) { // should error
>k : Symbol(k, Decl(cachedIterableTypesShouldAlwaysError.ts, 4, 11))
>obj : Symbol(obj, Decl(cachedIterableTypesShouldAlwaysError.ts, 0, 13))

void k;
>k : Symbol(k, Decl(cachedIterableTypesShouldAlwaysError.ts, 4, 11))
}

for (const k of obj) { // should error
>k : Symbol(k, Decl(cachedIterableTypesShouldAlwaysError.ts, 8, 11))
>obj : Symbol(obj, Decl(cachedIterableTypesShouldAlwaysError.ts, 0, 13))

void k;
>k : Symbol(k, Decl(cachedIterableTypesShouldAlwaysError.ts, 8, 11))
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
=== tests/cases/compiler/cachedIterableTypesShouldAlwaysError.ts ===
function foo(obj:
>foo : (obj: { x: "x"; [Symbol.iterator](): Generator<{ b: false; }>;} | { y: "y";}) => void
>obj : { x: "x"; [Symbol.iterator](): Generator<{ b: false;}>; } | { y: "y"; }

{ x: "x", [Symbol.iterator](): Generator<{ b: false }> } |
>x : "x"
>[Symbol.iterator] : () => Generator<{ b: false;}>
>Symbol.iterator : symbol
>Symbol : SymbolConstructor
>iterator : symbol
>b : false
>false : false

{ y: "y" }
>y : "y"

) {
for (const k of obj) { // should error
>k : any
>obj : { x: "x"; [Symbol.iterator](): Generator<{ b: false; }, any, unknown>; } | { y: "y"; }

void k;
>void k : undefined
>k : any
}

for (const k of obj) { // should error
>k : any
>obj : { x: "x"; [Symbol.iterator](): Generator<{ b: false; }, any, unknown>; } | { y: "y"; }

void k;
>void k : undefined
>k : any
}
}

Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
tests/cases/compiler/errorsInGenericTypeReference.ts(11,17): error TS2304: Cannot find name 'V'.
tests/cases/compiler/errorsInGenericTypeReference.ts(17,31): error TS2304: Cannot find name 'V'.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably not good. I am still pretty sure this has nothing to do with my changes, I just wanted to update the baseline references so my tests don't fail. Perhaps another issue should be opened for this case?

tests/cases/compiler/errorsInGenericTypeReference.ts(22,29): error TS2304: Cannot find name 'V'.
tests/cases/compiler/errorsInGenericTypeReference.ts(23,36): error TS2304: Cannot find name 'V'.
tests/cases/compiler/errorsInGenericTypeReference.ts(24,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
Expand All @@ -22,7 +21,7 @@ tests/cases/compiler/errorsInGenericTypeReference.ts(67,40): error TS2304: Canno
tests/cases/compiler/errorsInGenericTypeReference.ts(68,24): error TS2304: Cannot find name 'V'.


==== tests/cases/compiler/errorsInGenericTypeReference.ts (22 errors) ====
==== tests/cases/compiler/errorsInGenericTypeReference.ts (21 errors) ====
interface IFoo<T> { }

class Foo<T> { }
Expand All @@ -42,8 +41,6 @@ tests/cases/compiler/errorsInGenericTypeReference.ts(68,24): error TS2304: Canno
class testClass2<T> {
}
var tc2 = new testClass2<{ x: V }>(); // error: could not find symbol V
~
!!! error TS2304: Cannot find name 'V'.


// in method return type annotation
Expand Down
Loading