Skip to content

Commit 6bbe6d6

Browse files
authored
Fix return value and error reporting for getIterationTypesOfMethod (#50146)
1 parent bc7786b commit 6bbe6d6

File tree

11 files changed

+148
-62
lines changed

11 files changed

+148
-62
lines changed

src/compiler/checker.ts

Lines changed: 109 additions & 45 deletions
Large diffs are not rendered by default.
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
tests/cases/conformance/es6/for-ofStatements/for-of16.ts(8,11): error TS2489: An iterator must have a 'next()' method.
1+
tests/cases/conformance/es6/for-ofStatements/for-of16.ts(8,11): error TS2488: Type 'StringIterator' must have a '[Symbol.iterator]()' method that returns an iterator.
2+
tests/cases/conformance/es6/for-ofStatements/for-of16.ts(10,11): error TS2488: Type 'StringIterator' must have a '[Symbol.iterator]()' method that returns an iterator.
23

34

4-
==== tests/cases/conformance/es6/for-ofStatements/for-of16.ts (1 errors) ====
5+
==== tests/cases/conformance/es6/for-ofStatements/for-of16.ts (2 errors) ====
56
class StringIterator {
67
[Symbol.iterator]() {
78
return this;
@@ -11,4 +12,10 @@ tests/cases/conformance/es6/for-ofStatements/for-of16.ts(8,11): error TS2489: An
1112
var v: string;
1213
for (v of new StringIterator) { } // Should fail
1314
~~~~~~~~~~~~~~~~~~
14-
!!! error TS2489: An iterator must have a 'next()' method.
15+
!!! error TS2488: Type 'StringIterator' must have a '[Symbol.iterator]()' method that returns an iterator.
16+
!!! related TS2489 tests/cases/conformance/es6/for-ofStatements/for-of16.ts:8:11: An iterator must have a 'next()' method.
17+
18+
for (v of new StringIterator) { } // Should still fail (related errors should still be shown even though type is cached).
19+
~~~~~~~~~~~~~~~~~~
20+
!!! error TS2488: Type 'StringIterator' must have a '[Symbol.iterator]()' method that returns an iterator.
21+
!!! related TS2489 tests/cases/conformance/es6/for-ofStatements/for-of16.ts:10:11: An iterator must have a 'next()' method.

tests/baselines/reference/for-of16.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ class StringIterator {
66
}
77

88
var v: string;
9-
for (v of new StringIterator) { } // Should fail
9+
for (v of new StringIterator) { } // Should fail
10+
11+
for (v of new StringIterator) { } // Should still fail (related errors should still be shown even though type is cached).
1012

1113
//// [for-of16.js]
1214
class StringIterator {
@@ -16,3 +18,4 @@ class StringIterator {
1618
}
1719
var v;
1820
for (v of new StringIterator) { } // Should fail
21+
for (v of new StringIterator) { } // Should still fail (related errors should still be shown even though type is cached).

tests/baselines/reference/for-of16.symbols

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,7 @@ for (v of new StringIterator) { } // Should fail
2020
>v : Symbol(v, Decl(for-of16.ts, 6, 3))
2121
>StringIterator : Symbol(StringIterator, Decl(for-of16.ts, 0, 0))
2222

23+
for (v of new StringIterator) { } // Should still fail (related errors should still be shown even though type is cached).
24+
>v : Symbol(v, Decl(for-of16.ts, 6, 3))
25+
>StringIterator : Symbol(StringIterator, Decl(for-of16.ts, 0, 0))
26+

tests/baselines/reference/for-of16.types

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,8 @@ for (v of new StringIterator) { } // Should fail
2121
>new StringIterator : StringIterator
2222
>StringIterator : typeof StringIterator
2323

24+
for (v of new StringIterator) { } // Should still fail (related errors should still be shown even though type is cached).
25+
>v : string
26+
>new StringIterator : StringIterator
27+
>StringIterator : typeof StringIterator
28+
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck31.ts(2,11): error TS2322: Type 'Generator<(x: any) => any, void, any>' is not assignable to type '() => Iterable<(x: string) => number>'.
2-
Type 'Generator<(x: any) => any, void, any>' provides no match for the signature '(): Iterable<(x: string) => number>'.
1+
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck31.ts(2,11): error TS2322: Type 'Generator<(x: any) => any, void, unknown>' is not assignable to type '() => Iterable<(x: string) => number>'.
2+
Type 'Generator<(x: any) => any, void, unknown>' provides no match for the signature '(): Iterable<(x: string) => number>'.
33

44

55
==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck31.ts (1 errors) ====
@@ -10,6 +10,6 @@ tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck31.ts(2,11): erro
1010
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1111
} ()
1212
~~~~~~~~
13-
!!! error TS2322: Type 'Generator<(x: any) => any, void, any>' is not assignable to type '() => Iterable<(x: string) => number>'.
14-
!!! error TS2322: Type 'Generator<(x: any) => any, void, any>' provides no match for the signature '(): Iterable<(x: string) => number>'.
13+
!!! error TS2322: Type 'Generator<(x: any) => any, void, unknown>' is not assignable to type '() => Iterable<(x: string) => number>'.
14+
!!! error TS2322: Type 'Generator<(x: any) => any, void, unknown>' provides no match for the signature '(): Iterable<(x: string) => number>'.
1515
}

tests/baselines/reference/generatorTypeCheck31.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ function* g2(): Iterator<() => Iterable<(x: string) => number>> {
55

66
yield function* () {
77
>yield function* () { yield x => x.length; } () : undefined
8-
>function* () { yield x => x.length; } () : Generator<(x: any) => any, void, any>
9-
>function* () { yield x => x.length; } : () => Generator<(x: any) => any, void, any>
8+
>function* () { yield x => x.length; } () : Generator<(x: any) => any, void, unknown>
9+
>function* () { yield x => x.length; } : () => Generator<(x: any) => any, void, unknown>
1010

1111
yield x => x.length;
1212
>yield x => x.length : any
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck6.ts(1,17): error TS2322: Type 'Generator<any, any, any>' is not assignable to type 'number'.
1+
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck6.ts(1,17): error TS2322: Type 'Generator<any, any, unknown>' is not assignable to type 'number'.
22

33

44
==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck6.ts (1 errors) ====
55
function* g1(): number { }
66
~~~~~~
7-
!!! error TS2322: Type 'Generator<any, any, any>' is not assignable to type 'number'.
7+
!!! error TS2322: Type 'Generator<any, any, unknown>' is not assignable to type 'number'.

tests/baselines/reference/iteratorSpreadInArray10.errors.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tests/cases/conformance/es6/spread/iteratorSpreadInArray10.ts(7,17): error TS2489: An iterator must have a 'next()' method.
1+
tests/cases/conformance/es6/spread/iteratorSpreadInArray10.ts(7,17): error TS2488: Type 'SymbolIterator' must have a '[Symbol.iterator]()' method that returns an iterator.
22

33

44
==== tests/cases/conformance/es6/spread/iteratorSpreadInArray10.ts (1 errors) ====
@@ -10,4 +10,5 @@ tests/cases/conformance/es6/spread/iteratorSpreadInArray10.ts(7,17): error TS248
1010

1111
var array = [...new SymbolIterator];
1212
~~~~~~~~~~~~~~~~~~
13-
!!! error TS2489: An iterator must have a 'next()' method.
13+
!!! error TS2488: Type 'SymbolIterator' must have a '[Symbol.iterator]()' method that returns an iterator.
14+
!!! related TS2489 tests/cases/conformance/es6/spread/iteratorSpreadInArray10.ts:7:17: An iterator must have a 'next()' method.

tests/baselines/reference/types.asyncGenerators.es2018.2.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(
3636
tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(59,12): error TS2322: Type 'string' is not assignable to type 'number'.
3737
tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(62,12): error TS2322: Type 'string' is not assignable to type 'number'.
3838
tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(64,42): error TS2741: Property '[Symbol.iterator]' is missing in type 'AsyncGenerator<number, any, undefined>' but required in type 'IterableIterator<number>'.
39-
tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(67,42): error TS2741: Property '[Symbol.iterator]' is missing in type 'AsyncGenerator<any, any, any>' but required in type 'Iterable<number>'.
39+
tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(67,42): error TS2741: Property '[Symbol.iterator]' is missing in type 'AsyncGenerator<any, any, unknown>' but required in type 'Iterable<number>'.
4040
tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(70,42): error TS2322: Type 'AsyncGenerator<number, any, undefined>' is not assignable to type 'Iterator<number, any, undefined>'.
4141
The types returned by 'next(...)' are incompatible between these types.
4242
Type 'Promise<IteratorResult<number, any>>' is not assignable to type 'IteratorResult<number, any>'.
@@ -173,7 +173,7 @@ tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(
173173
}
174174
async function * explicitReturnType11(): Iterable<number> {
175175
~~~~~~~~~~~~~~~~
176-
!!! error TS2741: Property '[Symbol.iterator]' is missing in type 'AsyncGenerator<any, any, any>' but required in type 'Iterable<number>'.
176+
!!! error TS2741: Property '[Symbol.iterator]' is missing in type 'AsyncGenerator<any, any, unknown>' but required in type 'Iterable<number>'.
177177
!!! related TS2728 /.ts/lib.es2015.iterable.d.ts:51:5: '[Symbol.iterator]' is declared here.
178178
yield 1;
179179
}

tests/cases/conformance/es6/for-ofStatements/for-of16.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ class StringIterator {
66
}
77

88
var v: string;
9-
for (v of new StringIterator) { } // Should fail
9+
for (v of new StringIterator) { } // Should fail
10+
11+
for (v of new StringIterator) { } // Should still fail (related errors should still be shown even though type is cached).

0 commit comments

Comments
 (0)