summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2010-02-03 15:52:25 +0000
committerPaul Phillips <paulp@improving.org>2010-02-03 15:52:25 +0000
commit909924acba60dadee5647e405c0bb9a2676f4a70 (patch)
tree717f203151eff1771416d5649539491a6c69a8c1
parent0ae8343fd4822ae8c31325e3a9a03ea1a08ee237 (diff)
downloadscala-909924acba60dadee5647e405c0bb9a2676f4a70.tar.gz
scala-909924acba60dadee5647e405c0bb9a2676f4a70.tar.bz2
scala-909924acba60dadee5647e405c0bb9a2676f4a70.zip
Made sliding/grouped throw an exception when re...
Made sliding/grouped throw an exception when read past the end. Closes #3017.
-rw-r--r--src/library/scala/collection/Iterator.scala2
-rw-r--r--test/files/run/unittest_iterator.scala13
2 files changed, 15 insertions, 0 deletions
diff --git a/src/library/scala/collection/Iterator.scala b/src/library/scala/collection/Iterator.scala
index 4e8a409efd..2cee708869 100644
--- a/src/library/scala/collection/Iterator.scala
+++ b/src/library/scala/collection/Iterator.scala
@@ -937,6 +937,8 @@ trait Iterator[+A] { self =>
if (!filled)
fill()
+ if (!filled)
+ throw new NoSuchElementException("next on empty iterator")
filled = false
buffer.toList
}
diff --git a/test/files/run/unittest_iterator.scala b/test/files/run/unittest_iterator.scala
index 93aaa4a834..28a548160f 100644
--- a/test/files/run/unittest_iterator.scala
+++ b/test/files/run/unittest_iterator.scala
@@ -33,5 +33,18 @@ object Test
assertThat(1, (1 to 8).toList) { it.sliding(8, 8) withPartial false }
assertThat(2, List(9, 10, -1, -1, -1)) { it.sliding(5, 8) withPadding -1 }
assertThat(1, (1 to 5).toList) { it.sliding(5, 8) withPartial false }
+
+ // make sure it throws past th end
+ val thrown = try {
+ val it = List(1,2,3).sliding(2)
+ it.next
+ it.next
+ it.next
+ false
+ }
+ catch {
+ case _: NoSuchElementException => true
+ }
+ assert(thrown)
}
}