mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-04 21:53:42 -06:00
Fix infinite recursion in control flow analyzer inlining logic (#45845)
* Move inlineLevel counter to main type checker scope * Add regression test
This commit is contained in:
parent
e03600f257
commit
5b84512ccc
@ -333,6 +333,7 @@ namespace ts {
|
||||
let totalInstantiationCount = 0;
|
||||
let instantiationCount = 0;
|
||||
let instantiationDepth = 0;
|
||||
let inlineLevel = 0;
|
||||
let currentNode: Node | undefined;
|
||||
|
||||
const emptySymbols = createSymbolTable();
|
||||
@ -23247,7 +23248,6 @@ namespace ts {
|
||||
let key: string | undefined;
|
||||
let isKeySet = false;
|
||||
let flowDepth = 0;
|
||||
let inlineLevel = 0;
|
||||
if (flowAnalysisDisabled) {
|
||||
return errorType;
|
||||
}
|
||||
|
||||
@ -32,9 +32,11 @@ tests/cases/conformance/controlFlow/controlFlowAliasing.ts(267,13): error TS2322
|
||||
Type 'number' is not assignable to type 'string'.
|
||||
tests/cases/conformance/controlFlow/controlFlowAliasing.ts(270,13): error TS2322: Type 'string | number' is not assignable to type 'number'.
|
||||
Type 'string' is not assignable to type 'number'.
|
||||
tests/cases/conformance/controlFlow/controlFlowAliasing.ts(280,5): error TS2448: Block-scoped variable 'a' used before its declaration.
|
||||
tests/cases/conformance/controlFlow/controlFlowAliasing.ts(280,5): error TS2454: Variable 'a' is used before being assigned.
|
||||
|
||||
|
||||
==== tests/cases/conformance/controlFlow/controlFlowAliasing.ts (17 errors) ====
|
||||
==== tests/cases/conformance/controlFlow/controlFlowAliasing.ts (19 errors) ====
|
||||
// Narrowing by aliased conditional expressions
|
||||
|
||||
function f10(x: string | number) {
|
||||
@ -358,4 +360,19 @@ tests/cases/conformance/controlFlow/controlFlowAliasing.ts(270,13): error TS2322
|
||||
!!! error TS2322: Type 'string' is not assignable to type 'number'.
|
||||
}
|
||||
}
|
||||
|
||||
// Repro from #45830
|
||||
|
||||
const obj = {
|
||||
fn: () => true
|
||||
};
|
||||
|
||||
if (a) { }
|
||||
~
|
||||
!!! error TS2448: Block-scoped variable 'a' used before its declaration.
|
||||
!!! related TS2728 tests/cases/conformance/controlFlow/controlFlowAliasing.ts:282:7: 'a' is declared here.
|
||||
~
|
||||
!!! error TS2454: Variable 'a' is used before being assigned.
|
||||
|
||||
const a = obj.fn();
|
||||
|
||||
@ -271,6 +271,16 @@ function foo({ kind, payload }: Data) {
|
||||
let t: number = payload;
|
||||
}
|
||||
}
|
||||
|
||||
// Repro from #45830
|
||||
|
||||
const obj = {
|
||||
fn: () => true
|
||||
};
|
||||
|
||||
if (a) { }
|
||||
|
||||
const a = obj.fn();
|
||||
|
||||
|
||||
//// [controlFlowAliasing.js]
|
||||
@ -522,6 +532,12 @@ function foo(_a) {
|
||||
var t = payload;
|
||||
}
|
||||
}
|
||||
// Repro from #45830
|
||||
var obj = {
|
||||
fn: function () { return true; }
|
||||
};
|
||||
if (a) { }
|
||||
var a = obj.fn();
|
||||
|
||||
|
||||
//// [controlFlowAliasing.d.ts]
|
||||
@ -657,3 +673,7 @@ declare type Data = {
|
||||
};
|
||||
declare function gg2(obj: Data): void;
|
||||
declare function foo({ kind, payload }: Data): void;
|
||||
declare const obj: {
|
||||
fn: () => boolean;
|
||||
};
|
||||
declare const a: boolean;
|
||||
|
||||
@ -772,3 +772,22 @@ function foo({ kind, payload }: Data) {
|
||||
}
|
||||
}
|
||||
|
||||
// Repro from #45830
|
||||
|
||||
const obj = {
|
||||
>obj : Symbol(obj, Decl(controlFlowAliasing.ts, 275, 5))
|
||||
|
||||
fn: () => true
|
||||
>fn : Symbol(fn, Decl(controlFlowAliasing.ts, 275, 13))
|
||||
|
||||
};
|
||||
|
||||
if (a) { }
|
||||
>a : Symbol(a, Decl(controlFlowAliasing.ts, 281, 5))
|
||||
|
||||
const a = obj.fn();
|
||||
>a : Symbol(a, Decl(controlFlowAliasing.ts, 281, 5))
|
||||
>obj.fn : Symbol(fn, Decl(controlFlowAliasing.ts, 275, 13))
|
||||
>obj : Symbol(obj, Decl(controlFlowAliasing.ts, 275, 5))
|
||||
>fn : Symbol(fn, Decl(controlFlowAliasing.ts, 275, 13))
|
||||
|
||||
|
||||
@ -897,3 +897,26 @@ function foo({ kind, payload }: Data) {
|
||||
}
|
||||
}
|
||||
|
||||
// Repro from #45830
|
||||
|
||||
const obj = {
|
||||
>obj : { fn: () => boolean; }
|
||||
>{ fn: () => true} : { fn: () => boolean; }
|
||||
|
||||
fn: () => true
|
||||
>fn : () => boolean
|
||||
>() => true : () => boolean
|
||||
>true : true
|
||||
|
||||
};
|
||||
|
||||
if (a) { }
|
||||
>a : boolean
|
||||
|
||||
const a = obj.fn();
|
||||
>a : boolean
|
||||
>obj.fn() : boolean
|
||||
>obj.fn : () => boolean
|
||||
>obj : { fn: () => boolean; }
|
||||
>fn : () => boolean
|
||||
|
||||
|
||||
@ -273,3 +273,13 @@ function foo({ kind, payload }: Data) {
|
||||
let t: number = payload;
|
||||
}
|
||||
}
|
||||
|
||||
// Repro from #45830
|
||||
|
||||
const obj = {
|
||||
fn: () => true
|
||||
};
|
||||
|
||||
if (a) { }
|
||||
|
||||
const a = obj.fn();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user