summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/library/scala/collection/immutable/Stream.scala4
-rw-r--r--test/files/run/bug4697.check1
-rw-r--r--test/files/run/bug4697.scala8
3 files changed, 13 insertions, 0 deletions
diff --git a/src/library/scala/collection/immutable/Stream.scala b/src/library/scala/collection/immutable/Stream.scala
index 95ffaf5a3e..5f90202522 100644
--- a/src/library/scala/collection/immutable/Stream.scala
+++ b/src/library/scala/collection/immutable/Stream.scala
@@ -146,6 +146,10 @@ self =>
)
else super.++(that)(bf)
+ override def +:[B >: A, That](elem: B)(implicit bf: CanBuildFrom[Stream[A], B, That]): That =
+ if (isStreamBuilder(bf)) asThat(cons(elem, this))
+ else super.+:(elem)(bf)
+
/**
* Create a new stream which contains all intermediate results of applying the operator
* to subsequent elements left to right.
diff --git a/test/files/run/bug4697.check b/test/files/run/bug4697.check
new file mode 100644
index 0000000000..b9d569380c
--- /dev/null
+++ b/test/files/run/bug4697.check
@@ -0,0 +1 @@
+50005000
diff --git a/test/files/run/bug4697.scala b/test/files/run/bug4697.scala
new file mode 100644
index 0000000000..95592172e0
--- /dev/null
+++ b/test/files/run/bug4697.scala
@@ -0,0 +1,8 @@
+object Test {
+ var st = Stream(0)
+ for (i <- 1 to 10000) st = i +: st
+
+ def main(args: Array[String]): Unit = {
+ println(st.take(10000).sum)
+ }
+}