Make sure autoArrayType is unique, even if no lib is available (#20344)

* Make sure autoArrayType is unique, even if no lib is available

* fix typo
This commit is contained in:
Mohamed Hegazy 2017-12-01 19:51:14 -08:00 committed by GitHub
parent 1045d95a44
commit 59e5bbc393
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 90 additions and 0 deletions

View file

@ -25170,7 +25170,12 @@ namespace ts {
globalBooleanType = getGlobalType("Boolean" as __String, /*arity*/ 0, /*reportErrors*/ true);
globalRegExpType = getGlobalType("RegExp" as __String, /*arity*/ 0, /*reportErrors*/ true);
anyArrayType = createArrayType(anyType);
autoArrayType = createArrayType(autoType);
if (autoArrayType === emptyObjectType) {
// autoArrayType is used as a marker, so even if global Array type is not defined, it needs to be a unique type
autoArrayType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
}
globalReadonlyArrayType = <GenericType>getGlobalTypeOrUndefined("ReadonlyArray" as __String, /*arity*/ 1);
anyReadonlyArrayType = globalReadonlyArrayType ? createTypeFromGenericGlobalType(globalReadonlyArrayType, [anyType]) : anyArrayType;

View file

@ -0,0 +1,25 @@
error TS2318: Cannot find global type 'Array'.
error TS2318: Cannot find global type 'Boolean'.
error TS2318: Cannot find global type 'Function'.
error TS2318: Cannot find global type 'IArguments'.
error TS2318: Cannot find global type 'Number'.
error TS2318: Cannot find global type 'Object'.
error TS2318: Cannot find global type 'RegExp'.
error TS2318: Cannot find global type 'String'.
!!! error TS2318: Cannot find global type 'Array'.
!!! error TS2318: Cannot find global type 'Boolean'.
!!! error TS2318: Cannot find global type 'Function'.
!!! error TS2318: Cannot find global type 'IArguments'.
!!! error TS2318: Cannot find global type 'Number'.
!!! error TS2318: Cannot find global type 'Object'.
!!! error TS2318: Cannot find global type 'RegExp'.
!!! error TS2318: Cannot find global type 'String'.
==== tests/cases/compiler/noCrashOnNoLib.ts (0 errors) ====
export function f() {
let e: {}[];
while (true) {
e = [...(e || [])];
}
}

View file

@ -0,0 +1,18 @@
//// [noCrashOnNoLib.ts]
export function f() {
let e: {}[];
while (true) {
e = [...(e || [])];
}
}
//// [noCrashOnNoLib.js]
"use strict";
exports.__esModule = true;
function f() {
var e;
while (true) {
e = (e || []).slice();
}
}
exports.f = f;

View file

@ -0,0 +1,13 @@
=== tests/cases/compiler/noCrashOnNoLib.ts ===
export function f() {
>f : Symbol(f, Decl(noCrashOnNoLib.ts, 0, 0))
let e: {}[];
>e : Symbol(e, Decl(noCrashOnNoLib.ts, 1, 7))
while (true) {
e = [...(e || [])];
>e : Symbol(e, Decl(noCrashOnNoLib.ts, 1, 7))
>e : Symbol(e, Decl(noCrashOnNoLib.ts, 1, 7))
}
}

View file

@ -0,0 +1,21 @@
=== tests/cases/compiler/noCrashOnNoLib.ts ===
export function f() {
>f : () => void
let e: {}[];
>e : {}
while (true) {
>true : true
e = [...(e || [])];
>e = [...(e || [])] : {}
>e : {}
>[...(e || [])] : {}
>...(e || []) : any
>(e || []) : {}
>e || [] : {}
>e : {}
>[] : {}
}
}

View file

@ -0,0 +1,8 @@
// @noLib: true
export function f() {
let e: {}[];
while (true) {
e = [...(e || [])];
}
}