summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/library/scala/collection/immutable/Stream.scala3
-rw-r--r--test/files/run/t2176.check1
-rw-r--r--test/files/run/t2176.scala4
3 files changed, 7 insertions, 1 deletions
diff --git a/src/library/scala/collection/immutable/Stream.scala b/src/library/scala/collection/immutable/Stream.scala
index 9f609796f5..ad20214bbb 100644
--- a/src/library/scala/collection/immutable/Stream.scala
+++ b/src/library/scala/collection/immutable/Stream.scala
@@ -242,7 +242,8 @@ self =>
* @return the <code>n</code> first elements of this stream.
*/
override def take(n: Int): Stream[A] =
- if (n <= 0 || isEmpty) Stream.Empty else new Stream.Cons(head, tail take (n-1))
+ if (n <= 0 || isEmpty) Stream.Empty
+ else new Stream.Cons(head, if (n == 1) Stream.empty else tail take (n-1))
/** A substream starting at index `from`
* and extending up to (but not including) index `until`.
diff --git a/test/files/run/t2176.check b/test/files/run/t2176.check
new file mode 100644
index 0000000000..2298e8b6e9
--- /dev/null
+++ b/test/files/run/t2176.check
@@ -0,0 +1 @@
+Stream(1)
diff --git a/test/files/run/t2176.scala b/test/files/run/t2176.scala
new file mode 100644
index 0000000000..f8b07271a1
--- /dev/null
+++ b/test/files/run/t2176.scala
@@ -0,0 +1,4 @@
+object Test extends Application {
+ val res0 = Stream.cons(1, Stream.cons( { println("ouch"); 2 }, Stream.empty))
+ println(res0.take(1).force)
+}