Skip to content

Commit

Permalink
Track if incomplete variances have been observed
Browse files Browse the repository at this point in the history
  • Loading branch information
ahejlsberg committed Mar 2, 2022
1 parent de4a166 commit d059791
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ namespace ts {
let inlineLevel = 0;
let varianceLevel = 0;
let nestedVarianceSymbols: Symbol[] | undefined;
let incompleteVariancesObserved = false;
let currentNode: Node | undefined;

const emptySymbols = createSymbolTable();
Expand Down Expand Up @@ -20445,15 +20446,22 @@ namespace ts {
varianceLevel--;
// Recursive invocations of getVariancesWorker occur when two or more types circularly reference each
// other. In such cases, the nested invocations might observe in-process variance computations, i.e.
// cases where getVariancesWorker returns emptyArray, and thus might compute incomplete variances. For
// this reason we clear (and thus re-compute) the results of nested variance computations and only
// permanently record the outermost result. See #44572.
if (varianceLevel === 0 && nestedVarianceSymbols) {
for (const sym of nestedVarianceSymbols) getSymbolLinks(sym).variances = undefined;
// cases where getVariancesWorker returns emptyArray. If that happens we clear (and thus re-compute) the
// results of nested variance computations and only permanently record the outermost result. See #44572.
if (varianceLevel === 0) {
if (nestedVarianceSymbols && incompleteVariancesObserved) {
for (const sym of nestedVarianceSymbols) {
getSymbolLinks(sym).variances = undefined;
}
}
nestedVarianceSymbols = undefined;
incompleteVariancesObserved = false;
}
tracing?.pop();
}
else {
incompleteVariancesObserved ||= links.variances === emptyArray;
}
return links.variances;
}

Expand Down

0 comments on commit d059791

Please sign in to comment.