Merge pull request #31098 from andrewbranch/bug/30804
Fix crash checking spread element in loop
This commit is contained in:
commit
8c07b40cb6
6 changed files with 74 additions and 1 deletions
|
@ -21004,7 +21004,7 @@ namespace ts {
|
|||
// of the argument is a tuple type, spread the tuple elements into the argument list. We can
|
||||
// call checkExpressionCached because spread expressions never have a contextual type.
|
||||
const spreadArgument = <SpreadElement>args[length - 1];
|
||||
const type = checkExpressionCached(spreadArgument.expression);
|
||||
const type = flowLoopCount ? checkExpression(spreadArgument.expression) : checkExpressionCached(spreadArgument.expression);
|
||||
if (isTupleType(type)) {
|
||||
const typeArguments = (<TypeReference>type).typeArguments || emptyArray;
|
||||
const restIndex = type.target.hasRestElement ? typeArguments.length - 1 : -1;
|
||||
|
|
18
tests/baselines/reference/noImplicitAnyLoopCrash.errors.txt
Normal file
18
tests/baselines/reference/noImplicitAnyLoopCrash.errors.txt
Normal file
|
@ -0,0 +1,18 @@
|
|||
tests/cases/compiler/noImplicitAnyLoopCrash.ts(4,16): error TS2556: Expected 0 arguments, but got 1 or more.
|
||||
tests/cases/compiler/noImplicitAnyLoopCrash.ts(4,19): error TS2461: Type 'number' is not an array type.
|
||||
tests/cases/compiler/noImplicitAnyLoopCrash.ts(4,19): error TS2461: Type 'undefined' is not an array type.
|
||||
|
||||
|
||||
==== tests/cases/compiler/noImplicitAnyLoopCrash.ts (3 errors) ====
|
||||
let foo = () => {};
|
||||
let bar;
|
||||
while (1) {
|
||||
bar = ~foo(...bar);
|
||||
~~~~~~
|
||||
!!! error TS2556: Expected 0 arguments, but got 1 or more.
|
||||
~~~
|
||||
!!! error TS2461: Type 'number' is not an array type.
|
||||
~~~
|
||||
!!! error TS2461: Type 'undefined' is not an array type.
|
||||
}
|
||||
|
14
tests/baselines/reference/noImplicitAnyLoopCrash.js
Normal file
14
tests/baselines/reference/noImplicitAnyLoopCrash.js
Normal file
|
@ -0,0 +1,14 @@
|
|||
//// [noImplicitAnyLoopCrash.ts]
|
||||
let foo = () => {};
|
||||
let bar;
|
||||
while (1) {
|
||||
bar = ~foo(...bar);
|
||||
}
|
||||
|
||||
|
||||
//// [noImplicitAnyLoopCrash.js]
|
||||
var foo = function () { };
|
||||
var bar;
|
||||
while (1) {
|
||||
bar = ~foo.apply(void 0, bar);
|
||||
}
|
14
tests/baselines/reference/noImplicitAnyLoopCrash.symbols
Normal file
14
tests/baselines/reference/noImplicitAnyLoopCrash.symbols
Normal file
|
@ -0,0 +1,14 @@
|
|||
=== tests/cases/compiler/noImplicitAnyLoopCrash.ts ===
|
||||
let foo = () => {};
|
||||
>foo : Symbol(foo, Decl(noImplicitAnyLoopCrash.ts, 0, 3))
|
||||
|
||||
let bar;
|
||||
>bar : Symbol(bar, Decl(noImplicitAnyLoopCrash.ts, 1, 3))
|
||||
|
||||
while (1) {
|
||||
bar = ~foo(...bar);
|
||||
>bar : Symbol(bar, Decl(noImplicitAnyLoopCrash.ts, 1, 3))
|
||||
>foo : Symbol(foo, Decl(noImplicitAnyLoopCrash.ts, 0, 3))
|
||||
>bar : Symbol(bar, Decl(noImplicitAnyLoopCrash.ts, 1, 3))
|
||||
}
|
||||
|
21
tests/baselines/reference/noImplicitAnyLoopCrash.types
Normal file
21
tests/baselines/reference/noImplicitAnyLoopCrash.types
Normal file
|
@ -0,0 +1,21 @@
|
|||
=== tests/cases/compiler/noImplicitAnyLoopCrash.ts ===
|
||||
let foo = () => {};
|
||||
>foo : () => void
|
||||
>() => {} : () => void
|
||||
|
||||
let bar;
|
||||
>bar : any
|
||||
|
||||
while (1) {
|
||||
>1 : 1
|
||||
|
||||
bar = ~foo(...bar);
|
||||
>bar = ~foo(...bar) : number
|
||||
>bar : any
|
||||
>~foo(...bar) : number
|
||||
>foo(...bar) : void
|
||||
>foo : () => void
|
||||
>...bar : any
|
||||
>bar : number
|
||||
}
|
||||
|
6
tests/cases/compiler/noImplicitAnyLoopCrash.ts
Normal file
6
tests/cases/compiler/noImplicitAnyLoopCrash.ts
Normal file
|
@ -0,0 +1,6 @@
|
|||
// @noImplicitAny: true
|
||||
let foo = () => {};
|
||||
let bar;
|
||||
while (1) {
|
||||
bar = ~foo(...bar);
|
||||
}
|
Loading…
Reference in a new issue