Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Property handle imcomplete control flow types in nested loops
  • Loading branch information
ahejlsberg committed Aug 17, 2016
commit 2d1639fac81af24c2d015a5eca107a3c45ee11d4
15 changes: 13 additions & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8364,13 +8364,18 @@ namespace ts {
// each antecedent code path.
const antecedentTypes: Type[] = [];
let subtypeReduction = false;
let firstAntecedentType: FlowType;
flowLoopNodes[flowLoopCount] = flow;
flowLoopKeys[flowLoopCount] = key;
flowLoopTypes[flowLoopCount] = antecedentTypes;
for (const antecedent of flow.antecedents) {
flowLoopCount++;
const type = getTypeFromFlowType(getTypeAtFlowNode(antecedent));
const flowType = getTypeAtFlowNode(antecedent);
flowLoopCount--;
if (!firstAntecedentType) {
firstAntecedentType = flowType;
}
const type = getTypeFromFlowType(flowType);
// If we see a value appear in the cache it is a sign that control flow analysis
// was restarted and completed by checkExpressionCached. We can simply pick up
// the resulting type and bail out.
Expand All @@ -8393,7 +8398,13 @@ namespace ts {
break;
}
}
return cache[key] = getUnionType(antecedentTypes, subtypeReduction);
// The result is incomplete if the first antecedent (the non-looping control flow path)
// is incomplete.
const result = getUnionType(antecedentTypes, subtypeReduction);
if (isIncomplete(firstAntecedentType)) {
return createFlowType(result, /*incomplete*/ true);
}
return cache[key] = result;
}

function isMatchingReferenceDiscriminant(expr: Expression) {
Expand Down