mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-06 04:35:21 -05:00
fix(42088): fix crash on unreachability condition in for statement (#42110)
This commit is contained in:
@@ -21966,8 +21966,12 @@ namespace ts {
|
||||
return some((<FlowLabel>flow).antecedents, f => isReachableFlowNodeWorker(f, /*noCacheCheck*/ false));
|
||||
}
|
||||
else if (flags & FlowFlags.LoopLabel) {
|
||||
const antecedents = (<FlowLabel>flow).antecedents;
|
||||
if (antecedents === undefined || antecedents.length === 0) {
|
||||
return false;
|
||||
}
|
||||
// A loop is reachable if the control flow path that leads to the top is reachable.
|
||||
flow = (<FlowLabel>flow).antecedents![0];
|
||||
flow = antecedents[0];
|
||||
}
|
||||
else if (flags & FlowFlags.SwitchClause) {
|
||||
// The control flow path representing an unmatched value in a switch statement with
|
||||
|
||||
17
tests/baselines/reference/reachabilityChecks8.errors.txt
Normal file
17
tests/baselines/reference/reachabilityChecks8.errors.txt
Normal file
@@ -0,0 +1,17 @@
|
||||
tests/cases/compiler/reachabilityChecks8.ts(4,24): error TS7027: Unreachable code detected.
|
||||
tests/cases/compiler/reachabilityChecks8.ts(5,24): error TS7027: Unreachable code detected.
|
||||
|
||||
|
||||
==== tests/cases/compiler/reachabilityChecks8.ts (2 errors) ====
|
||||
try {
|
||||
for (
|
||||
(function () { throw "1"; })();
|
||||
(function () { throw "2"; })();
|
||||
~~~~~~~~~~
|
||||
!!! error TS7027: Unreachable code detected.
|
||||
(function () { throw "3"; })()
|
||||
~~~~~~~~~~
|
||||
!!! error TS7027: Unreachable code detected.
|
||||
) {}
|
||||
} catch (e) {}
|
||||
|
||||
15
tests/baselines/reference/reachabilityChecks8.js
Normal file
15
tests/baselines/reference/reachabilityChecks8.js
Normal file
@@ -0,0 +1,15 @@
|
||||
//// [reachabilityChecks8.ts]
|
||||
try {
|
||||
for (
|
||||
(function () { throw "1"; })();
|
||||
(function () { throw "2"; })();
|
||||
(function () { throw "3"; })()
|
||||
) {}
|
||||
} catch (e) {}
|
||||
|
||||
|
||||
//// [reachabilityChecks8.js]
|
||||
try {
|
||||
for ((function () { throw "1"; })(); (function () { throw "2"; })(); (function () { throw "3"; })()) { }
|
||||
}
|
||||
catch (e) { }
|
||||
10
tests/baselines/reference/reachabilityChecks8.symbols
Normal file
10
tests/baselines/reference/reachabilityChecks8.symbols
Normal file
@@ -0,0 +1,10 @@
|
||||
=== tests/cases/compiler/reachabilityChecks8.ts ===
|
||||
try {
|
||||
for (
|
||||
(function () { throw "1"; })();
|
||||
(function () { throw "2"; })();
|
||||
(function () { throw "3"; })()
|
||||
) {}
|
||||
} catch (e) {}
|
||||
>e : Symbol(e, Decl(reachabilityChecks8.ts, 6, 9))
|
||||
|
||||
25
tests/baselines/reference/reachabilityChecks8.types
Normal file
25
tests/baselines/reference/reachabilityChecks8.types
Normal file
@@ -0,0 +1,25 @@
|
||||
=== tests/cases/compiler/reachabilityChecks8.ts ===
|
||||
try {
|
||||
for (
|
||||
(function () { throw "1"; })();
|
||||
>(function () { throw "1"; })() : never
|
||||
>(function () { throw "1"; }) : () => never
|
||||
>function () { throw "1"; } : () => never
|
||||
>"1" : "1"
|
||||
|
||||
(function () { throw "2"; })();
|
||||
>(function () { throw "2"; })() : never
|
||||
>(function () { throw "2"; }) : () => never
|
||||
>function () { throw "2"; } : () => never
|
||||
>"2" : "2"
|
||||
|
||||
(function () { throw "3"; })()
|
||||
>(function () { throw "3"; })() : never
|
||||
>(function () { throw "3"; }) : () => never
|
||||
>function () { throw "3"; } : () => never
|
||||
>"3" : "3"
|
||||
|
||||
) {}
|
||||
} catch (e) {}
|
||||
>e : any
|
||||
|
||||
9
tests/cases/compiler/reachabilityChecks8.ts
Normal file
9
tests/cases/compiler/reachabilityChecks8.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
// @allowUnreachableCode: false
|
||||
|
||||
try {
|
||||
for (
|
||||
(function () { throw "1"; })();
|
||||
(function () { throw "2"; })();
|
||||
(function () { throw "3"; })()
|
||||
) {}
|
||||
} catch (e) {}
|
||||
Reference in New Issue
Block a user