Skip to content

Commit cafec55

Browse files
committed
Properly handle try-finally statements in isReachableFlowNode
1 parent ba30fdc commit cafec55

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/compiler/checker.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17003,6 +17003,10 @@ namespace ts {
1700317003
return result;
1700417004
}
1700517005

17006+
function isUnlockedReachableFlowNode(flow: FlowNode) {
17007+
return !(flow.flags & FlowFlags.PreFinally && (<PreFinallyFlow>flow).lock.locked) && isReachableFlowNodeWorker(flow, /*skipCacheCheck*/ false);
17008+
}
17009+
1700617010
function isReachableFlowNodeWorker(flow: FlowNode, noCacheCheck: boolean): boolean {
1700717011
while (true) {
1700817012
if (flow === lastFlowNode) {
@@ -17017,8 +17021,8 @@ namespace ts {
1701717021
}
1701817022
noCacheCheck = false;
1701917023
}
17020-
if (flags & (FlowFlags.Assignment | FlowFlags.Condition | FlowFlags.ArrayMutation | FlowFlags.PreFinally | FlowFlags.AfterFinally)) {
17021-
flow = (<FlowAssignment | FlowCondition | FlowArrayMutation | PreFinallyFlow | AfterFinallyFlow>flow).antecedent;
17024+
if (flags & (FlowFlags.Assignment | FlowFlags.Condition | FlowFlags.ArrayMutation | FlowFlags.PreFinally)) {
17025+
flow = (<FlowAssignment | FlowCondition | FlowArrayMutation | PreFinallyFlow>flow).antecedent;
1702217026
}
1702317027
else if (flags & FlowFlags.Call) {
1702417028
const signature = getEffectsSignature((<FlowCall>flow).node);
@@ -17029,7 +17033,7 @@ namespace ts {
1702917033
}
1703017034
else if (flags & FlowFlags.BranchLabel) {
1703117035
// A branching point is reachable if any branch is reachable.
17032-
return some((<FlowLabel>flow).antecedents, isReachableFlowNode);
17036+
return some((<FlowLabel>flow).antecedents, isUnlockedReachableFlowNode);
1703317037
}
1703417038
else if (flags & FlowFlags.LoopLabel) {
1703517039
// A loop is reachable if the control flow path that leads to the top is reachable.
@@ -17043,6 +17047,14 @@ namespace ts {
1704317047
}
1704417048
flow = (<FlowSwitchClause>flow).antecedent;
1704517049
}
17050+
else if (flags & FlowFlags.AfterFinally) {
17051+
// Cache is unreliable once we start locking nodes
17052+
lastFlowNode = undefined;
17053+
(<AfterFinallyFlow>flow).locked = true;
17054+
const result = isReachableFlowNodeWorker((<AfterFinallyFlow>flow).antecedent, /*skipCacheCheck*/ false);
17055+
(<AfterFinallyFlow>flow).locked = false;
17056+
return result;
17057+
}
1704617058
else {
1704717059
return !(flags & FlowFlags.Unreachable);
1704817060
}

0 commit comments

Comments
 (0)