Skip to content

Commit

Permalink
Propegate saved variance flags from cached comparisons
Browse files Browse the repository at this point in the history
  • Loading branch information
weswigham committed May 31, 2019
1 parent 22348d8 commit 20c928e
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12981,6 +12981,17 @@ namespace ts {
return result;
}

function propegateSidebandVarianceFlags(variances: VarianceFlags[]) {
if (outofbandVarianceMarkerHandler) {
if (some(variances, v => !!(v & VarianceFlags.Unmeasurable))) {
outofbandVarianceMarkerHandler(/*onlyUnreliable*/ false);
}
if (some(variances, v => !!(v & VarianceFlags.Unreliable))) {
outofbandVarianceMarkerHandler(/*onlyUnreliable*/ true);
}
}
}

// Determine if possibly recursive types are related. First, check if the result is already available in the global cache.
// Second, check if we have already started a comparison of the given two types in which case we assume the result to be true.
// Third, check if both types are part of deeply nested chains of generic type instantiations and if so assume the types are
Expand All @@ -12998,6 +13009,16 @@ namespace ts {
// as a failure, and should be updated as a reported failure by the bottom of this function.
}
else {
if (outofbandVarianceMarkerHandler) {
// We're in the middle of variance checking - integrate any unmeasurable/unreliable flags from this cached component
if (source.flags & (TypeFlags.Object | TypeFlags.Conditional) && source.aliasSymbol &&
source.aliasTypeArguments && source.aliasSymbol === target.aliasSymbol) {
propegateSidebandVarianceFlags(getAliasVariances(source.aliasSymbol));
}
if (getObjectFlags(source) & ObjectFlags.Reference && getObjectFlags(target) & ObjectFlags.Reference && (<TypeReference>source).target === (<TypeReference>target).target) {
propegateSidebandVarianceFlags(getVariances((<TypeReference>source).target));
}
}
return related === RelationComparisonResult.Succeeded ? Ternary.True : Ternary.False;
}
}
Expand Down

0 comments on commit 20c928e

Please sign in to comment.