Skip to content

Commit

Permalink
Defer computation of isDistributionDependent to avoid circularities
Browse files Browse the repository at this point in the history
  • Loading branch information
ahejlsberg committed Oct 22, 2021
1 parent f2f35ae commit d6f5ace
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
15 changes: 8 additions & 7 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15638,14 +15638,16 @@ namespace ts {
return result;
}

function isDistributionDependent(root: ConditionalRoot) {
return root.isDistributive && (
isTypeParameterPossiblyReferenced(root.checkType as TypeParameter, root.node.trueType) ||
isTypeParameterPossiblyReferenced(root.checkType as TypeParameter, root.node.falseType));
}

function getTypeFromConditionalTypeNode(node: ConditionalTypeNode): Type {
const links = getNodeLinks(node);
if (!links.resolvedType) {
const checkType = getTypeFromTypeNode(node.checkType);
const isDistributive = !!(checkType.flags & TypeFlags.TypeParameter);
const isDistributionDependent = isDistributive && (
isTypeParameterPossiblyReferenced(checkType as TypeParameter, node.trueType) ||
isTypeParameterPossiblyReferenced(checkType as TypeParameter, node.falseType));
const aliasSymbol = getAliasSymbolForTypeNode(node);
const aliasTypeArguments = getTypeArgumentsForAliasSymbol(aliasSymbol);
const allOuterTypeParameters = getOuterTypeParameters(node, /*includeThisTypes*/ true);
Expand All @@ -15654,8 +15656,7 @@ namespace ts {
node,
checkType,
extendsType: getTypeFromTypeNode(node.extendsType),
isDistributive,
isDistributionDependent,
isDistributive: !!(checkType.flags & TypeFlags.TypeParameter),
inferTypeParameters: getInferTypeParameters(node),
outerTypeParameters,
instantiations: undefined,
Expand Down Expand Up @@ -19032,7 +19033,7 @@ namespace ts {
// We check for a relationship to a conditional type target only when the conditional type has no
// 'infer' positions and is not distributive or is distributive but doesn't reference the check type
// parameter in either of the result types.
if (!c.root.inferTypeParameters && !c.root.isDistributionDependent) {
if (!c.root.inferTypeParameters && !isDistributionDependent(c.root)) {
// Check if the conditional is always true or always false but still deferred for distribution purposes.
const skipTrue = !isTypeAssignableTo(getPermissiveInstantiation(c.checkType), getPermissiveInstantiation(c.extendsType));
const skipFalse = !skipTrue && isTypeAssignableTo(getRestrictiveInstantiation(c.checkType), getRestrictiveInstantiation(c.extendsType));
Expand Down
1 change: 0 additions & 1 deletion src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5648,7 +5648,6 @@ namespace ts {
checkType: Type;
extendsType: Type;
isDistributive: boolean;
isDistributionDependent: boolean;
inferTypeParameters?: TypeParameter[];
outerTypeParameters?: TypeParameter[];
instantiations?: Map<Type>;
Expand Down

0 comments on commit d6f5ace

Please sign in to comment.