scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
232 stars 21 forks source link

IterableWrapper no longer delegates equals #12683

Closed som-snytt closed 2 years ago

som-snytt commented 2 years ago

Reproduction steps

scala 2.13.8> import scala.jdk.CollectionConverters._
import scala.jdk.CollectionConverters._

scala 2.13.8> Nil.asJavaCollection == Nil.asJavaCollection
val res0: Boolean = true

scala 2.13.8> Set("foo").asJavaCollection == Set("foo").asJavaCollection
val res1: Boolean = true
scala 2.13.10> import scala.jdk.CollectionConverters._
import scala.jdk.CollectionConverters._

scala 2.13.10> Nil.asJavaCollection == Nil.asJavaCollection
val res0: Boolean = false

scala 2.13.10> Set("foo").asJavaCollection == Set("foo").asJavaCollection
val res1: Boolean = false

Problem

It would be nice if it behaved the same. A wrapper should delegate if possible.

Arguably, there is no contract for structural equality:

scala> def f = new java.util.AbstractCollection[Int] {
     | def size = 3; def iterator = Iterator(1,2,3).asJava }
def f: java.util.AbstractCollection[Int]

scala> f == f
val res0: Boolean = false

Therefore, there should be no expectation here.

Usage of correct API restores expectations:

scala 2.13.10> Set("foo").asJava == Set("foo").asJava
val res2: Boolean = true

Reported at https://github.com/scala/scala/pull/10104#issuecomment-1297233492

som-snytt commented 2 years ago

Actually, case class equality is terrible, as it says the Collection is only equal to wrapped thing. That is poor semantics.

RustedBones commented 1 year ago

We should probably re-open this one as the fix in 2.13.11 was only implemented for IterableWrapper and still fails for other wrapper like JIterableWrapper.

som-snytt commented 1 year ago

@RustedBones feel free to open a new ticket. I don't remember the details.