summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Suereth <joshua.suereth@gmail.com>2012-08-29 15:50:13 -0400
committerJosh Suereth <joshua.suereth@gmail.com>2012-08-29 15:50:13 -0400
commitdb94e06b1c11b9afdc0fd9a18e456e0774fabd80 (patch)
tree27d5e5fcb76d746e4889a2051ec569bba5cd2eaa
parente03a5b766be27a1f43c9151a611b04519a2b15df (diff)
downloadscala-db94e06b1c11b9afdc0fd9a18e456e0774fabd80.tar.gz
scala-db94e06b1c11b9afdc0fd9a18e456e0774fabd80.tar.bz2
scala-db94e06b1c11b9afdc0fd9a18e456e0774fabd80.zip
Fixed cloning a double-linked list.
Still need to determine if this is a systemic issue and needs to be addressed higher in the linked list hierarchy. For now, just fixing the reported bug, with a note here for other maintainers.
-rw-r--r--src/library/scala/collection/mutable/DoubleLinkedList.scala7
-rw-r--r--test/files/run/t6292.scala18
2 files changed, 25 insertions, 0 deletions
diff --git a/src/library/scala/collection/mutable/DoubleLinkedList.scala b/src/library/scala/collection/mutable/DoubleLinkedList.scala
index cba4e9725e..b7c5f07502 100644
--- a/src/library/scala/collection/mutable/DoubleLinkedList.scala
+++ b/src/library/scala/collection/mutable/DoubleLinkedList.scala
@@ -63,6 +63,13 @@ class DoubleLinkedList[A]() extends AbstractSeq[A]
}
override def companion: GenericCompanion[DoubleLinkedList] = DoubleLinkedList
+
+ // Accurately clone this collection. See SI-6296
+ override def clone(): DoubleLinkedList[A] = {
+ val builder = newBuilder
+ builder ++= this
+ builder.result
+ }
}
/** $factoryInfo
diff --git a/test/files/run/t6292.scala b/test/files/run/t6292.scala
new file mode 100644
index 0000000000..51e31f95fc
--- /dev/null
+++ b/test/files/run/t6292.scala
@@ -0,0 +1,18 @@
+ import scala.collection.mutable.DoubleLinkedList
+
+object Test {
+ def main(args: Array[String]): Unit = {
+ cloneAndtest(DoubleLinkedList[Int]())
+ cloneAndtest(DoubleLinkedList[Int](1))
+ cloneAndtest(DoubleLinkedList[Int](1,2,3,4))
+ }
+
+ def cloneAndtest(l: DoubleLinkedList[Int]): Unit =
+ testSame(l, l.clone.asInstanceOf[DoubleLinkedList[Int]])
+
+ def testSame(one: DoubleLinkedList[Int], two: DoubleLinkedList[Int]): Unit = {
+ def msg = s" for ${one} and ${two} !"
+ assert(one.size == two.size, s"Cloned sizes are not the same $msg!")
+ assert(one == two, s"Cloned lists are not equal $msg")
+ }
+}