scala / bug

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

`collection.Seq` factory doesn't preserve `collection.Seq`s #12669

Closed lrytz closed 1 year ago

lrytz commented 1 year ago
Welcome to Scala 2.13.10 (OpenJDK 64-Bit Server VM, Java 17.0.1).
Type in expressions for evaluation. Or try :help.

scala> import collection.mutable
import collection.mutable

scala> val s: collection.Seq[Int] = mutable.ArraySeq(1)
val s: scala.collection.Seq[Int] = ArraySeq(1)

scala> val es = s.to(collection.Seq)
val es: scala.collection.Seq[Int] = List(1)

scala> es eq s
val res0: Boolean = false
lrytz commented 1 year ago

Hmm, probably that's by design, to can return the same instance for immutable collections, but is otherwise supposed to create a copy.

scala> val s = mutable.ArraySeq(1,2,3)
val s: scala.collection.mutable.ArraySeq[Int] = ArraySeq(1, 2, 3)

scala> s.to(mutable.Seq) eq s
val res1: Boolean = false
SethTisue commented 1 year ago

Pretty sure there was a design discussion about this in not the too distant past, though I don't recall what the outcome was. I can dig for it later. cc @scala/collections

SethTisue commented 1 year ago

Also let's check and make sure that the Scaladoc is totally explicit on this point.