Skip to content

Fix circular constraint check #25913

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 8 commits into from
Jul 25, 2018
Merged

Fix circular constraint check #25913

merged 8 commits into from
Jul 25, 2018

Conversation

ahejlsberg
Copy link
Member

This PR ensures that we consistently call getConstraintOfTypeParameter to obtain type parameter constraints. The getConstraintOfTypeParameter method protects against circular constraints, unlike the lower level getConstraintFromTypeParameter helper function.

Fixes #25740.

@ahejlsberg ahejlsberg requested review from weswigham and mhegazy July 24, 2018 23:20
@ahejlsberg
Copy link
Member Author

When reviewing the baseline changes, note that the "disappearing" constraints are all in situations where a circularity error is also being reported. We now consistently remove constraints when they are circular.

const bc = (<Type>target).immediateBaseConstraint;
return !!bc && bc !== circularConstraintType;
}

return Debug.fail("Unhandled TypeSystemPropertyName " + propertyName);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While you're here revising this, it might be worth replacing Debug.fail( with Debug.asserNever(propertyName to guarantee exhaustiveness. Just a nit.

Copy link
Member

@weswigham weswigham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but it might be worth commenting on getConstraintOfTypeParameter and/or getConstraintFromTypeParameter as to the nature of both and to which one you probably meant to use (similar to our comment on getContextualType that reads "Woah! Do you really want to use this function?").

@ahejlsberg ahejlsberg merged commit dd4fd8c into master Jul 25, 2018
@ahejlsberg ahejlsberg deleted the fixCircularConstraintCheck branch July 25, 2018 13:46
@mhegazy mhegazy mentioned this pull request Jul 25, 2018
mhegazy added a commit that referenced this pull request Jul 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants