Skip to content

Commit 8c07b40

Browse files
authored
Merge pull request #31098 from andrewbranch/bug/30804
Fix crash checking spread element in loop
2 parents 5fb6bbe + 89497fc commit 8c07b40

File tree

6 files changed

+74
-1
lines changed

6 files changed

+74
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21004,7 +21004,7 @@ namespace ts {
2100421004
// of the argument is a tuple type, spread the tuple elements into the argument list. We can
2100521005
// call checkExpressionCached because spread expressions never have a contextual type.
2100621006
const spreadArgument = <SpreadElement>args[length - 1];
21007-
const type = checkExpressionCached(spreadArgument.expression);
21007+
const type = flowLoopCount ? checkExpression(spreadArgument.expression) : checkExpressionCached(spreadArgument.expression);
2100821008
if (isTupleType(type)) {
2100921009
const typeArguments = (<TypeReference>type).typeArguments || emptyArray;
2101021010
const restIndex = type.target.hasRestElement ? typeArguments.length - 1 : -1;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
tests/cases/compiler/noImplicitAnyLoopCrash.ts(4,16): error TS2556: Expected 0 arguments, but got 1 or more.
2+
tests/cases/compiler/noImplicitAnyLoopCrash.ts(4,19): error TS2461: Type 'number' is not an array type.
3+
tests/cases/compiler/noImplicitAnyLoopCrash.ts(4,19): error TS2461: Type 'undefined' is not an array type.
4+
5+
6+
==== tests/cases/compiler/noImplicitAnyLoopCrash.ts (3 errors) ====
7+
let foo = () => {};
8+
let bar;
9+
while (1) {
10+
bar = ~foo(...bar);
11+
~~~~~~
12+
!!! error TS2556: Expected 0 arguments, but got 1 or more.
13+
~~~
14+
!!! error TS2461: Type 'number' is not an array type.
15+
~~~
16+
!!! error TS2461: Type 'undefined' is not an array type.
17+
}
18+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//// [noImplicitAnyLoopCrash.ts]
2+
let foo = () => {};
3+
let bar;
4+
while (1) {
5+
bar = ~foo(...bar);
6+
}
7+
8+
9+
//// [noImplicitAnyLoopCrash.js]
10+
var foo = function () { };
11+
var bar;
12+
while (1) {
13+
bar = ~foo.apply(void 0, bar);
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
=== tests/cases/compiler/noImplicitAnyLoopCrash.ts ===
2+
let foo = () => {};
3+
>foo : Symbol(foo, Decl(noImplicitAnyLoopCrash.ts, 0, 3))
4+
5+
let bar;
6+
>bar : Symbol(bar, Decl(noImplicitAnyLoopCrash.ts, 1, 3))
7+
8+
while (1) {
9+
bar = ~foo(...bar);
10+
>bar : Symbol(bar, Decl(noImplicitAnyLoopCrash.ts, 1, 3))
11+
>foo : Symbol(foo, Decl(noImplicitAnyLoopCrash.ts, 0, 3))
12+
>bar : Symbol(bar, Decl(noImplicitAnyLoopCrash.ts, 1, 3))
13+
}
14+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
=== tests/cases/compiler/noImplicitAnyLoopCrash.ts ===
2+
let foo = () => {};
3+
>foo : () => void
4+
>() => {} : () => void
5+
6+
let bar;
7+
>bar : any
8+
9+
while (1) {
10+
>1 : 1
11+
12+
bar = ~foo(...bar);
13+
>bar = ~foo(...bar) : number
14+
>bar : any
15+
>~foo(...bar) : number
16+
>foo(...bar) : void
17+
>foo : () => void
18+
>...bar : any
19+
>bar : number
20+
}
21+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// @noImplicitAny: true
2+
let foo = () => {};
3+
let bar;
4+
while (1) {
5+
bar = ~foo(...bar);
6+
}

0 commit comments

Comments
 (0)