Skip to content

Commit 59e5bbc

Browse files
authored
Make sure autoArrayType is unique, even if no lib is available (microsoft#20344)
* Make sure autoArrayType is unique, even if no lib is available * fix typo
1 parent 1045d95 commit 59e5bbc

6 files changed

Lines changed: 90 additions & 0 deletions

File tree

src/compiler/checker.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25170,7 +25170,12 @@ namespace ts {
2517025170
globalBooleanType = getGlobalType("Boolean" as __String, /*arity*/ 0, /*reportErrors*/ true);
2517125171
globalRegExpType = getGlobalType("RegExp" as __String, /*arity*/ 0, /*reportErrors*/ true);
2517225172
anyArrayType = createArrayType(anyType);
25173+
2517325174
autoArrayType = createArrayType(autoType);
25175+
if (autoArrayType === emptyObjectType) {
25176+
// autoArrayType is used as a marker, so even if global Array type is not defined, it needs to be a unique type
25177+
autoArrayType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
25178+
}
2517425179

2517525180
globalReadonlyArrayType = <GenericType>getGlobalTypeOrUndefined("ReadonlyArray" as __String, /*arity*/ 1);
2517625181
anyReadonlyArrayType = globalReadonlyArrayType ? createTypeFromGenericGlobalType(globalReadonlyArrayType, [anyType]) : anyArrayType;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
error TS2318: Cannot find global type 'Array'.
2+
error TS2318: Cannot find global type 'Boolean'.
3+
error TS2318: Cannot find global type 'Function'.
4+
error TS2318: Cannot find global type 'IArguments'.
5+
error TS2318: Cannot find global type 'Number'.
6+
error TS2318: Cannot find global type 'Object'.
7+
error TS2318: Cannot find global type 'RegExp'.
8+
error TS2318: Cannot find global type 'String'.
9+
10+
11+
!!! error TS2318: Cannot find global type 'Array'.
12+
!!! error TS2318: Cannot find global type 'Boolean'.
13+
!!! error TS2318: Cannot find global type 'Function'.
14+
!!! error TS2318: Cannot find global type 'IArguments'.
15+
!!! error TS2318: Cannot find global type 'Number'.
16+
!!! error TS2318: Cannot find global type 'Object'.
17+
!!! error TS2318: Cannot find global type 'RegExp'.
18+
!!! error TS2318: Cannot find global type 'String'.
19+
==== tests/cases/compiler/noCrashOnNoLib.ts (0 errors) ====
20+
export function f() {
21+
let e: {}[];
22+
while (true) {
23+
e = [...(e || [])];
24+
}
25+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//// [noCrashOnNoLib.ts]
2+
export function f() {
3+
let e: {}[];
4+
while (true) {
5+
e = [...(e || [])];
6+
}
7+
}
8+
9+
//// [noCrashOnNoLib.js]
10+
"use strict";
11+
exports.__esModule = true;
12+
function f() {
13+
var e;
14+
while (true) {
15+
e = (e || []).slice();
16+
}
17+
}
18+
exports.f = f;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
=== tests/cases/compiler/noCrashOnNoLib.ts ===
2+
export function f() {
3+
>f : Symbol(f, Decl(noCrashOnNoLib.ts, 0, 0))
4+
5+
let e: {}[];
6+
>e : Symbol(e, Decl(noCrashOnNoLib.ts, 1, 7))
7+
8+
while (true) {
9+
e = [...(e || [])];
10+
>e : Symbol(e, Decl(noCrashOnNoLib.ts, 1, 7))
11+
>e : Symbol(e, Decl(noCrashOnNoLib.ts, 1, 7))
12+
}
13+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
=== tests/cases/compiler/noCrashOnNoLib.ts ===
2+
export function f() {
3+
>f : () => void
4+
5+
let e: {}[];
6+
>e : {}
7+
8+
while (true) {
9+
>true : true
10+
11+
e = [...(e || [])];
12+
>e = [...(e || [])] : {}
13+
>e : {}
14+
>[...(e || [])] : {}
15+
>...(e || []) : any
16+
>(e || []) : {}
17+
>e || [] : {}
18+
>e : {}
19+
>[] : {}
20+
}
21+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// @noLib: true
2+
3+
export function f() {
4+
let e: {}[];
5+
while (true) {
6+
e = [...(e || [])];
7+
}
8+
}

0 commit comments

Comments
 (0)