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
Comparing Option[T] to T shouldn't be silently compiled #5426
Comments
Imported From: https://issues.scala-lang.org/browse/SI-5426?orig=1 |
@paulp said: scala> println(y == x)
<console>:10: warning: comparing values of types Int and Some[Int] using `==' will always yield false
println(y == x)
^ a) is not going to happen, equals must be symmetric. b) is not going to happen either. A warning might be possible, but it's harder than it looks to warn where you want to without creating spurious warnings elsewhere. |
@paulp said: |
Maciej Pilichowski (macias) said: But if 2.10 will fix this, it is OK with me. |
@paulp said: |
Maciej Pilichowski (macias) said: |
@retronym said: |
@SethTisue said (edited on Jul 11, 2012 10:07:18 PM UTC): |
Do not warn if the comparison is within a Seq |
Is there a compiler flag for this? |
@avbhandaru you can ask on https://users.scala-lang.org or https://discord.com/invite/scala |
Consider such code
"false" will be printed. Actually, Scala compares those entities in such way that it will be ALWAYS false, so it is indication user didn't want to write the way she/he did (same case when you compare Int to null for example -- you will get at least warning). But here -- nothing, compiler happily compiles the code.
Possible solutions:
a) compiler should evaluate None == Value always to false, and Some(Value) == Value always to true (I prefer such solution)
b) forbid comparing Option[T] to T (compiler error)
b.1) or at least warning
The text was updated successfully, but these errors were encountered: