Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Equals sensibility warnings imprecise for case classes #5663
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.
Imported From: https://issues.scala-lang.org/browse/SI-5663?orig=1
It's not possible to run partest without -deprecation.
(The deprecated feature here was trait extends Kase,
I tried supplying a .javaopts file to turn off the default