@@ -17309,24 +17309,31 @@ namespace ts {
17309
17309
const antecedentTypes: Type[] = [];
17310
17310
let subtypeReduction = false;
17311
17311
let firstAntecedentType: FlowType | undefined;
17312
- flowLoopNodes[flowLoopCount] = flow;
17313
- flowLoopKeys[flowLoopCount] = key;
17314
- flowLoopTypes[flowLoopCount] = antecedentTypes;
17315
17312
for (const antecedent of flow.antecedents!) {
17316
- flowLoopCount++;
17317
- const flowType = getTypeAtFlowNode(antecedent);
17318
- flowLoopCount--;
17313
+ let flowType;
17319
17314
if (!firstAntecedentType) {
17320
- firstAntecedentType = flowType;
17315
+ // The first antecedent of a loop junction is always the non-looping control
17316
+ // flow path that leads to the top.
17317
+ flowType = firstAntecedentType = getTypeAtFlowNode(antecedent);
17321
17318
}
17322
- const type = getTypeFromFlowType(flowType);
17323
- // If we see a value appear in the cache it is a sign that control flow analysis
17324
- // was restarted and completed by checkExpressionCached. We can simply pick up
17325
- // the resulting type and bail out.
17326
- const cached = cache.get(key);
17327
- if (cached) {
17328
- return cached;
17319
+ else {
17320
+ // All but the first antecedent are the looping control flow paths that lead
17321
+ // back to the loop junction. We track these on the flow loop stack.
17322
+ flowLoopNodes[flowLoopCount] = flow;
17323
+ flowLoopKeys[flowLoopCount] = key;
17324
+ flowLoopTypes[flowLoopCount] = antecedentTypes;
17325
+ flowLoopCount++;
17326
+ flowType = getTypeAtFlowNode(antecedent);
17327
+ flowLoopCount--;
17328
+ // If we see a value appear in the cache it is a sign that control flow analysis
17329
+ // was restarted and completed by checkExpressionCached. We can simply pick up
17330
+ // the resulting type and bail out.
17331
+ const cached = cache.get(key);
17332
+ if (cached) {
17333
+ return cached;
17334
+ }
17329
17335
}
17336
+ const type = getTypeFromFlowType(flowType);
17330
17337
pushIfUnique(antecedentTypes, type);
17331
17338
// If an antecedent type is not a subset of the declared type, we need to perform
17332
17339
// subtype reduction. This happens when a "foreign" type is injected into the control
0 commit comments