Skip to content

Commit 20c928e

Browse files
committed
Propegate saved variance flags from cached comparisons
1 parent 22348d8 commit 20c928e

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/compiler/checker.ts

+21
Original file line numberDiff line numberDiff line change
@@ -12981,6 +12981,17 @@ namespace ts {
1298112981
return result;
1298212982
}
1298312983

12984+
function propegateSidebandVarianceFlags(variances: VarianceFlags[]) {
12985+
if (outofbandVarianceMarkerHandler) {
12986+
if (some(variances, v => !!(v & VarianceFlags.Unmeasurable))) {
12987+
outofbandVarianceMarkerHandler(/*onlyUnreliable*/ false);
12988+
}
12989+
if (some(variances, v => !!(v & VarianceFlags.Unreliable))) {
12990+
outofbandVarianceMarkerHandler(/*onlyUnreliable*/ true);
12991+
}
12992+
}
12993+
}
12994+
1298412995
// Determine if possibly recursive types are related. First, check if the result is already available in the global cache.
1298512996
// Second, check if we have already started a comparison of the given two types in which case we assume the result to be true.
1298612997
// Third, check if both types are part of deeply nested chains of generic type instantiations and if so assume the types are
@@ -12998,6 +13009,16 @@ namespace ts {
1299813009
// as a failure, and should be updated as a reported failure by the bottom of this function.
1299913010
}
1300013011
else {
13012+
if (outofbandVarianceMarkerHandler) {
13013+
// We're in the middle of variance checking - integrate any unmeasurable/unreliable flags from this cached component
13014+
if (source.flags & (TypeFlags.Object | TypeFlags.Conditional) && source.aliasSymbol &&
13015+
source.aliasTypeArguments && source.aliasSymbol === target.aliasSymbol) {
13016+
propegateSidebandVarianceFlags(getAliasVariances(source.aliasSymbol));
13017+
}
13018+
if (getObjectFlags(source) & ObjectFlags.Reference && getObjectFlags(target) & ObjectFlags.Reference && (<TypeReference>source).target === (<TypeReference>target).target) {
13019+
propegateSidebandVarianceFlags(getVariances((<TypeReference>source).target));
13020+
}
13021+
}
1300113022
return related === RelationComparisonResult.Succeeded ? Ternary.True : Ternary.False;
1300213023
}
1300313024
}

0 commit comments

Comments
 (0)