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

IterableWrapper no longer delegates equals #12683

Closed
som-snytt opened this issue Oct 31, 2022 · 3 comments · Fixed by scala/scala#10205
Closed

IterableWrapper no longer delegates equals #12683

som-snytt opened this issue Oct 31, 2022 · 3 comments · Fixed by scala/scala#10205

Comments

@som-snytt
Copy link

som-snytt commented Oct 31, 2022

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 scala/scala#10104 (comment)

@som-snytt
Copy link
Author

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

@RustedBones
Copy link

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
Copy link
Author

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

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

Successfully merging a pull request may close this issue.

3 participants