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

Provide CanEqual for Option (Option == None), Throwables, and other #15521

Open
strelec opened this issue Jun 24, 2022 · 6 comments
Open

Provide CanEqual for Option (Option == None), Throwables, and other #15521

strelec opened this issue Jun 24, 2022 · 6 comments

Comments

@strelec
Copy link

strelec commented Jun 24, 2022

Minimized code

x match {
  case Some(value) =>
  case None =>
}

Output

[error] 129 |					case None =>
[error]     |					     ^^^^
[error]     |					     Values of types object None and Option[T] cannot be compared with == or !=.
[error]     |					     I found:
[error]     |
[error]     |					         CanEqual.canEqualOptions[T, U](/* missing */summon[CanEqual[T, U]])
[error]     |
[error]     |					     But no implicit values were found that match type CanEqual[T, U].

Expectation

CanEqual instance should come already defined for at the very least, the standard library. You have to strike a balance between versatility and usability.

As it is currently, -language:strictEquality is too cautious to be useful.

@strelec strelec added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jun 24, 2022
@strelec strelec changed the title Provide CanEqual for Throwables and collection classes (for Option == None) Provide CanEqual for Option (Option == None), Throwables, and other Jun 24, 2022
@odersky
Copy link
Contributor

odersky commented Jun 25, 2022

The problem is that the CanEqual instance would logically have to be in the companion object of Option. But we cannot touch the standard library for the time being, since we want to use 2.13.

At some point we need to decide that we will ship a Scala 3 specific standard library, and in that case CanEqual instances would be provided. Until then, I agree that -language:strictEquality is not useful and should be avoided.

@odersky odersky added itype:enhancement stat:on hold and removed stat:needs triage Every issue needs to have an "area" and "itype" label itype:bug labels Jun 25, 2022
@nicolasstucki
Copy link
Contributor

We may be able to synthesize that instance while we still use the 2.13 library

@odersky
Copy link
Contributor

odersky commented Jun 26, 2022

Synthesizing looks very hard when we need to put the CanEqual in Option, where it belongs. Yes, we could shadow Option, but it's a maintainability nightmare to track any changes in the 2.13 version of Option from then on.

Maybe we should deprecate strictEquality instead. It was really meant only as a demonstrator to show that the system would support that. But given the present state of libraries it's not useful, so we should discourage people from trying to make it work.

@strelec
Copy link
Author

strelec commented Jun 26, 2022

I agree with @odersky here about deprecating strictEquality. And that is okay, things are experimental for a reason.

Being a scala user for almost 10 years now, it is the first feature I did not really like. So much boilerplate just to get a bit better type safety. And it feels I was fighting it the whole way. I also do not like it generates a method with a bunch of lazy val fields the JVM bytecode (I thought it was erased at compile time).

I think that the solution that outputs a compiler warning (or heck, even an error) when two things cannot possibly be equal would be a step gap solution that could serve us for years.

Eventually we will find a proper solution that will still be playing nicely with the JVM. But that will require some serious out out the box idea, so let's not commit to a solution in question just yet.

@kevin-lee
Copy link
Contributor

kevin-lee commented Jul 8, 2022

@strelec Do you still have this problem? Are you using Scala 3.0.x?
It should be fixed by #12419 and #13265 in Scala 3.1.0 and higher.

@ckipp01
Copy link
Member

ckipp01 commented May 24, 2023

I'm unable to reproduce this with

//> using scala 3.nightly
//> using options -Wunused:all -language:strictEquality

object Test:
  val x: Option[String] = None
  x match {
    case Some(value) =>
    case None        =>
  }

Can this be closed, or am I missing something from your original case @strelec

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants