Skip to content

Commit 4582e49

Browse files
ahejlsbergmprobst
authored andcommitted
Defer computation of isDistributionDependent to avoid circularities (microsoft#46474)
* Defer computation of isDistributionDependent to avoid circularities * Accept new API baselines
1 parent 187f421 commit 4582e49

File tree

4 files changed

+8
-10
lines changed

4 files changed

+8
-10
lines changed

src/compiler/checker.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15638,14 +15638,16 @@ namespace ts {
1563815638
return result;
1563915639
}
1564015640

15641+
function isDistributionDependent(root: ConditionalRoot) {
15642+
return root.isDistributive && (
15643+
isTypeParameterPossiblyReferenced(root.checkType as TypeParameter, root.node.trueType) ||
15644+
isTypeParameterPossiblyReferenced(root.checkType as TypeParameter, root.node.falseType));
15645+
}
15646+
1564115647
function getTypeFromConditionalTypeNode(node: ConditionalTypeNode): Type {
1564215648
const links = getNodeLinks(node);
1564315649
if (!links.resolvedType) {
1564415650
const checkType = getTypeFromTypeNode(node.checkType);
15645-
const isDistributive = !!(checkType.flags & TypeFlags.TypeParameter);
15646-
const isDistributionDependent = isDistributive && (
15647-
isTypeParameterPossiblyReferenced(checkType as TypeParameter, node.trueType) ||
15648-
isTypeParameterPossiblyReferenced(checkType as TypeParameter, node.falseType));
1564915651
const aliasSymbol = getAliasSymbolForTypeNode(node);
1565015652
const aliasTypeArguments = getTypeArgumentsForAliasSymbol(aliasSymbol);
1565115653
const allOuterTypeParameters = getOuterTypeParameters(node, /*includeThisTypes*/ true);
@@ -15654,8 +15656,7 @@ namespace ts {
1565415656
node,
1565515657
checkType,
1565615658
extendsType: getTypeFromTypeNode(node.extendsType),
15657-
isDistributive,
15658-
isDistributionDependent,
15659+
isDistributive: !!(checkType.flags & TypeFlags.TypeParameter),
1565915660
inferTypeParameters: getInferTypeParameters(node),
1566015661
outerTypeParameters,
1566115662
instantiations: undefined,
@@ -19032,7 +19033,7 @@ namespace ts {
1903219033
// We check for a relationship to a conditional type target only when the conditional type has no
1903319034
// 'infer' positions and is not distributive or is distributive but doesn't reference the check type
1903419035
// parameter in either of the result types.
19035-
if (!c.root.inferTypeParameters && !c.root.isDistributionDependent) {
19036+
if (!c.root.inferTypeParameters && !isDistributionDependent(c.root)) {
1903619037
// Check if the conditional is always true or always false but still deferred for distribution purposes.
1903719038
const skipTrue = !isTypeAssignableTo(getPermissiveInstantiation(c.checkType), getPermissiveInstantiation(c.extendsType));
1903819039
const skipFalse = !skipTrue && isTypeAssignableTo(getRestrictiveInstantiation(c.checkType), getRestrictiveInstantiation(c.extendsType));

src/compiler/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5648,7 +5648,6 @@ namespace ts {
56485648
checkType: Type;
56495649
extendsType: Type;
56505650
isDistributive: boolean;
5651-
isDistributionDependent: boolean;
56525651
inferTypeParameters?: TypeParameter[];
56535652
outerTypeParameters?: TypeParameter[];
56545653
instantiations?: Map<Type>;

tests/baselines/reference/api/tsserverlibrary.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2747,7 +2747,6 @@ declare namespace ts {
27472747
checkType: Type;
27482748
extendsType: Type;
27492749
isDistributive: boolean;
2750-
isDistributionDependent: boolean;
27512750
inferTypeParameters?: TypeParameter[];
27522751
outerTypeParameters?: TypeParameter[];
27532752
instantiations?: Map<Type>;

tests/baselines/reference/api/typescript.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2747,7 +2747,6 @@ declare namespace ts {
27472747
checkType: Type;
27482748
extendsType: Type;
27492749
isDistributive: boolean;
2750-
isDistributionDependent: boolean;
27512750
inferTypeParameters?: TypeParameter[];
27522751
outerTypeParameters?: TypeParameter[];
27532752
instantiations?: Map<Type>;

0 commit comments

Comments
 (0)