Skip to content

Defer computation of isDistributionDependent to avoid circularities #46474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
1 change: 0 additions & 1 deletion tests/baselines/reference/api/tsserverlibrary.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2747,7 +2747,6 @@ declare namespace ts {
checkType: Type;
extendsType: Type;
isDistributive: boolean;
isDistributionDependent: boolean;
inferTypeParameters?: TypeParameter[];
outerTypeParameters?: TypeParameter[];
instantiations?: Map<Type>;
Expand Down
1 change: 0 additions & 1 deletion tests/baselines/reference/api/typescript.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2747,7 +2747,6 @@ declare namespace ts {
checkType: Type;
extendsType: Type;
isDistributive: boolean;
isDistributionDependent: boolean;
inferTypeParameters?: TypeParameter[];
outerTypeParameters?: TypeParameter[];
instantiations?: Map<Type>;
Expand Down