-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Equatability of Nothing with types which are otherwise unequatable #13512
Comments
Strict equality is not really set up to work with the current standard library. You can use it to experiment with your own types. The idea is that with enough experience gained we can do a better job on the next redesign of the standard library. We need a lot more experiments with what the right givens for the various bits of equality would be. But I won't have the time to do it myself. But if others want to add new givens, run the community build and report back, that would be welcome! |
@odersky after posting this I had the nagging thought that it should be possible to derive CanEqual for equatable types with Nothing, as CanEqual is contravariant. Indeed under 3.0.2:
So there is a real bug here in that synthetic CanEqual for primitives fails to consider Nothing as a possible subtype: |
I've opened an issue for synthetic CanEqual in #13739 so it doesn't get missed, however the question of whether or not Nothing should be equatable with any other type regardless of its equatability remains. |
PR: #13828 |
I have been experimenting with strict equality in 3.0.2 and immediately ran into the issue where you cannot pattern match against Nil/None. I see the efforts to address this in 3.1.0 in 3e963c0 and 32a99fd, however I am not sure that this is the correct approach, as the following is still illegal:
This can be addressed by instead adding the following givens permitting equating
Nothing
with any type regardless of the equatability of that type, on the basis that you could never actually invoke the equality test:With this addition it appears you can remove the supplementary
CanEqual.canEqual{Seq,Option}
previously added to address matching Nil/None in the above-mentioned commits.I will note that you do get this awkward behavior already present in 2.x:
this could perhaps be addressed by adding an overload to
Any
, however I am uncertain of the viability of such an approach:The text was updated successfully, but these errors were encountered: