Skip to content

Commit 8e97b45

Browse files
Copilotandrewbranch
andcommitted
Fix missing error for function call spread in iterator parameter validation
Co-authored-by: andrewbranch <[email protected]>
1 parent 7273d6d commit 8e97b45

9 files changed

+27
-104
lines changed

internal/checker/checker.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5905,7 +5905,10 @@ func (c *Checker) getIterationTypesOfIterable(t *Type, use IterationUse, errorNo
59055905
return cached
59065906
}
59075907
result := c.getIterationTypesOfIterableWorker(t, use, errorNode)
5908-
c.iterationTypesCache[key] = result
5908+
// Don't cache empty results when error reporting is requested, to ensure errors are reported for each call site
5909+
if result.hasTypes() || errorNode == nil {
5910+
c.iterationTypesCache[key] = result
5911+
}
59095912
return result
59105913
}
59115914

testdata/baselines/reference/submodule/compiler/iteratorExtraParameters.errors.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
iteratorExtraParameters.ts(11,21): error TS2488: Type '{ [Symbol.iterator](_: number): Generator<number, void, unknown>; }' must have a '[Symbol.iterator]()' method that returns an iterator.
22
iteratorExtraParameters.ts(13,12): error TS2488: Type '{ [Symbol.iterator](_: number): Generator<number, void, unknown>; }' must have a '[Symbol.iterator]()' method that returns an iterator.
33
iteratorExtraParameters.ts(15,9): error TS2488: Type '{ [Symbol.iterator](_: number): Generator<number, void, unknown>; }' must have a '[Symbol.iterator]()' method that returns an iterator.
4+
iteratorExtraParameters.ts(17,10): error TS2488: Type '{ [Symbol.iterator](_: number): Generator<number, void, unknown>; }' must have a '[Symbol.iterator]()' method that returns an iterator.
45

56

6-
==== iteratorExtraParameters.ts (3 errors) ====
7+
==== iteratorExtraParameters.ts (4 errors) ====
78
// https://github.com/microsoft/TypeScript/issues/57130
89
const iter = {
910
*[Symbol.iterator](_: number) {
@@ -39,5 +40,11 @@ iteratorExtraParameters.ts(15,9): error TS2488: Type '{ [Symbol.iterator](_: num
3940
Target signature provides too few arguments. Expected 1 or more, but got 0.
4041

4142
g(...iter);
43+
~~~~
44+
!!! error TS2488: Type '{ [Symbol.iterator](_: number): Generator<number, void, unknown>; }' must have a '[Symbol.iterator]()' method that returns an iterator.
45+
!!! related TS2322 iteratorExtraParameters.ts:17:10: Type '{ [Symbol.iterator](_: number): Generator<number, void, unknown>; }' is not assignable to type 'Iterable<T, TReturn, TNext>'.
46+
Types of property '[Symbol.iterator]' are incompatible.
47+
Type '(_: number) => Generator<number, void, unknown>' is not assignable to type '() => Iterator<T, TReturn, TNext>'.
48+
Target signature provides too few arguments. Expected 1 or more, but got 0.
4249
}
4350

testdata/baselines/reference/submodule/compiler/iteratorExtraParameters.errors.txt.diff

Lines changed: 0 additions & 28 deletions
This file was deleted.

testdata/baselines/reference/submodule/compiler/omittedExpressionForOfLoop.errors.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
omittedExpressionForOfLoop.ts(1,19): error TS2304: Cannot find name 'doesNotExist'.
22
omittedExpressionForOfLoop.ts(4,19): error TS18050: The value 'undefined' cannot be used here.
33
omittedExpressionForOfLoop.ts(7,12): error TS2488: Type 'never' must have a '[Symbol.iterator]()' method that returns an iterator.
4+
omittedExpressionForOfLoop.ts(10,12): error TS2488: Type 'never' must have a '[Symbol.iterator]()' method that returns an iterator.
45

56

6-
==== omittedExpressionForOfLoop.ts (3 errors) ====
7+
==== omittedExpressionForOfLoop.ts (4 errors) ====
78
for (const [,] of doesNotExist) {
89
~~~~~~~~~~~~
910
!!! error TS2304: Cannot find name 'doesNotExist'.
@@ -20,4 +21,6 @@ omittedExpressionForOfLoop.ts(7,12): error TS2488: Type 'never' must have a '[Sy
2021
}
2122

2223
for (const [] of []) {
24+
~~
25+
!!! error TS2488: Type 'never' must have a '[Symbol.iterator]()' method that returns an iterator.
2326
}

testdata/baselines/reference/submodule/compiler/omittedExpressionForOfLoop.errors.txt.diff

Lines changed: 0 additions & 23 deletions
This file was deleted.

testdata/baselines/reference/submodule/conformance/for-of16.errors.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
for-of16.ts(8,11): error TS2488: Type 'MyStringIterator' must have a '[Symbol.iterator]()' method that returns an iterator.
2+
for-of16.ts(10,11): error TS2488: Type 'MyStringIterator' must have a '[Symbol.iterator]()' method that returns an iterator.
23

34

4-
==== for-of16.ts (1 errors) ====
5+
==== for-of16.ts (2 errors) ====
56
class MyStringIterator {
67
[Symbol.iterator]() {
78
return this;
@@ -14,4 +15,7 @@ for-of16.ts(8,11): error TS2488: Type 'MyStringIterator' must have a '[Symbol.it
1415
!!! error TS2488: Type 'MyStringIterator' must have a '[Symbol.iterator]()' method that returns an iterator.
1516
!!! related TS2489 for-of16.ts:8:11: An iterator must have a 'next()' method.
1617

17-
for (v of new MyStringIterator) { } // Should still fail (related errors should still be shown even though type is cached).
18+
for (v of new MyStringIterator) { } // Should still fail (related errors should still be shown even though type is cached).
19+
~~~~~~~~~~~~~~~~~~~~
20+
!!! error TS2488: Type 'MyStringIterator' must have a '[Symbol.iterator]()' method that returns an iterator.
21+
!!! related TS2489 for-of16.ts:10:11: An iterator must have a 'next()' method.

testdata/baselines/reference/submodule/conformance/for-of16.errors.txt.diff

Lines changed: 0 additions & 21 deletions
This file was deleted.

testdata/baselines/reference/submodule/conformance/types.forAwait.es2018.2.errors.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ types.forAwait.es2018.2.ts(8,21): error TS2504: Type '{}' must have a '[Symbol.a
33
types.forAwait.es2018.2.ts(10,16): error TS2322: Type 'number' is not assignable to type 'string'.
44
types.forAwait.es2018.2.ts(12,16): error TS2322: Type 'number' is not assignable to type 'string'.
55
types.forAwait.es2018.2.ts(14,21): error TS2488: Type 'AsyncIterable<number>' must have a '[Symbol.iterator]()' method that returns an iterator.
6+
types.forAwait.es2018.2.ts(16,15): error TS2488: Type 'AsyncIterable<number>' must have a '[Symbol.iterator]()' method that returns an iterator.
67

78

8-
==== types.forAwait.es2018.2.ts (5 errors) ====
9+
==== types.forAwait.es2018.2.ts (6 errors) ====
910
declare const asyncIterable: AsyncIterable<number>;
1011
declare const iterable: Iterable<number>;
1112
async function f() {
@@ -33,6 +34,9 @@ types.forAwait.es2018.2.ts(14,21): error TS2488: Type 'AsyncIterable<number>' mu
3334
!!! related TS2773 types.forAwait.es2018.2.ts:14:21: Did you forget to use 'await'?
3435
}
3536
for (y of asyncIterable) {
37+
~~~~~~~~~~~~~
38+
!!! error TS2488: Type 'AsyncIterable<number>' must have a '[Symbol.iterator]()' method that returns an iterator.
39+
!!! related TS2773 types.forAwait.es2018.2.ts:16:15: Did you forget to use 'await'?
3640
}
3741
}
3842

testdata/baselines/reference/submodule/conformance/types.forAwait.es2018.2.errors.txt.diff

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)