Skip to content

Fix circular constraint check#25913

Merged
ahejlsberg merged 8 commits into
masterfrom
fixCircularConstraintCheck
Jul 25, 2018
Merged

Fix circular constraint check#25913
ahejlsberg merged 8 commits into
masterfrom
fixCircularConstraintCheck

Conversation

@ahejlsberg
Copy link
Copy Markdown
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 mhegazy and weswigham July 24, 2018 23:20
@ahejlsberg
Copy link
Copy Markdown
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.

Comment thread src/compiler/checker.ts Outdated
return !!bc && bc !== circularConstraintType;
}

return Debug.fail("Unhandled TypeSystemPropertyName " + propertyName);
Copy link
Copy Markdown
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
Copy Markdown
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
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants