summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/library/scala/collection/mutable/ListBuffer.scala9
-rw-r--r--test/files/run/bug4656.check1
-rw-r--r--test/files/run/bug4656.scala13
3 files changed, 21 insertions, 2 deletions
diff --git a/src/library/scala/collection/mutable/ListBuffer.scala b/src/library/scala/collection/mutable/ListBuffer.scala
index 6a75108dfb..f1271627c1 100644
--- a/src/library/scala/collection/mutable/ListBuffer.scala
+++ b/src/library/scala/collection/mutable/ListBuffer.scala
@@ -245,9 +245,14 @@ final class ListBuffer[A]
*
* @param xs the list to which elements are prepended
*/
- def prependToList(xs: List[A]): List[A] =
+ def prependToList(xs: List[A]): List[A] = {
if (start.isEmpty) xs
- else { last0.tl = xs; toList }
+ else {
+ if (exported) copy()
+ last0.tl = xs
+ toList
+ }
+ }
// Overrides of methods in Buffer
diff --git a/test/files/run/bug4656.check b/test/files/run/bug4656.check
new file mode 100644
index 0000000000..15a62794a9
--- /dev/null
+++ b/test/files/run/bug4656.check
@@ -0,0 +1 @@
+List(1, 2, 3)
diff --git a/test/files/run/bug4656.scala b/test/files/run/bug4656.scala
new file mode 100644
index 0000000000..4f3d189c8f
--- /dev/null
+++ b/test/files/run/bug4656.scala
@@ -0,0 +1,13 @@
+object Test {
+ def f = {
+ val buf = new collection.mutable.ListBuffer[Int]
+ buf ++= List(1, 2, 3)
+ val l = buf.toList
+ buf prependToList List(4, 5, 6)
+ l
+ }
+
+ def main(args: Array[String]): Unit = {
+ println(f)
+ }
+}