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

Equals sensibility warnings imprecise for case classes #5663

Closed
scabug opened this issue Apr 12, 2012 · 3 comments
Closed

Equals sensibility warnings imprecise for case classes #5663

scabug opened this issue Apr 12, 2012 · 3 comments
Assignees
Labels
Milestone

Comments

@scabug
Copy link

@scabug scabug commented Apr 12, 2012

This is related to #5648, warnings on comparisons.

There is one edge-casey bug: (new Kase() == kaseAlias) causes the "fresh object" warning. It should be either no warning or "unrelated types" warning, depending on the types.

The similar comparison (finalKase == kaseAlias) will emit "always yield false" (if there is no subtype relationship) instead of the weaker "unrelated types" warnings. (Can be true if the types are siblings extending the case class.)

The useful improvement would be to handle comparisons between case classes again, since if the case classes are different they can't satisfy the synthetic equals. (Some(1) == Thing(1))

A couple of related improvements would be to tighten up "fresh object" warnings, of the form (new Some(1) == None).

scala> :paste
// Entering paste mode (ctrl-D to finish)

// alias
trait Thingy

// sibling classes that extend a case class
case class Thing(i: Int)
class ThingOne(x:Int) extends Thing(x)
class ThingTwo(y:Int) extends Thing(y) with Thingy
final class ThingThree(z:Int) extends Thing(z)

val t1 = new ThingOne(11)
val t2: Thingy = new ThingTwo(11)
val t4 = new ThingThree(11)

// Exiting paste mode, now interpreting.

defined trait Thingy
defined class Thing
defined class ThingOne
defined class ThingTwo
defined class ThingThree
t1: ThingOne = Thing(11)
t2: Thingy = Thing(11)
t4: ThingThree = Thing(11)

scala> (new ThingTwo(11) == t2)
<console>:13: warning: comparing a fresh object using `==' will always yield false
              (new ThingTwo(11) == t2)
                                ^
res0: Boolean = true

scala> (t4 == t2)  // unrelated types
<console>:15: warning: comparing values of types ThingThree and Thingy using `==' will always yield false
              (t4 == t2)
                  ^
res1: Boolean = true

scala> (Some(1) == Thing(1))  // could warn
res2: Boolean = false

I'll prepare a pull if I can type faster than Paul.

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Apr 12, 2012

Imported From: https://issues.scala-lang.org/browse/SI-5663?orig=1
Reporter: @som-snytt
Affected Versions: 2.10.0
Other Milestones: 2.10.0-M3

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Apr 13, 2012

@som-snytt said:
scala/scala#392

It's not possible to run partest without -deprecation.
Since detecting the warnings requires a neg test with
-Xfatal-warnings, and deprecation terminates the compile.
During a deprecation cycle, it seems necessary to test
deprecated features (e.g., warnings).

(The deprecated feature here was trait extends Kase,
where the case class is parenless.)

I tried supplying a .javaopts file to turn off the default
-deprecation, without success. On a related note, I would
expect to be able to "scalac --deprecation=false".

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Apr 28, 2012

@som-snytt said:
commit 72d86cbe8cb4792a2eae190aee3677854bffb89f

@scabug scabug closed this Apr 28, 2012
@scabug scabug added the help wanted label Apr 7, 2017
@scabug scabug added this to the 2.10.0-M2 milestone Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.