Skip to content
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

Fix comparable in switch #11633

Merged
merged 10 commits into from
Nov 10, 2016
Merged

Fix comparable in switch #11633

merged 10 commits into from
Nov 10, 2016

Conversation

sandersn
Copy link
Member

Fixes #10892

switch should use the same rules as ===, so I pushed the calls to getBaseTypeOfLiteralType into isTypeEqualityComparableTo, which both checkBinaryLikeExpression and checkSwitchStatement call.

switch was missing the rule for converting literal types to the literal
base type if needed.
Since all callers need this check -- it's how equality is supposed to
work everywhere.
There are more literal types in error messages because error reporting
no longer has the advantage of calls to getBaseLiteralType
@sandersn
Copy link
Member Author

@DanielRosenwasser I found a pretty good solution to make this fix cleaner. It drops more literal types into error messages, but is otherwise not bad.

@sandersn
Copy link
Member Author

@DanielRosenwasser I believe you knew about this code since you refactored comparability this year. Can you review it?

@DanielRosenwasser
Copy link
Member

@aozgaa weren't you working on a similar bug regarding intersection type comparability? What was the outcome of that?

@ahejlsberg
Copy link
Member

👍

@sandersn sandersn merged commit 6398e0d into master Nov 10, 2016
@sandersn sandersn deleted the fix-comparable-in-switch branch November 10, 2016 17:20
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
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.

4 participants