diff --git a/src/library/scala/collection/Iterator.scala b/src/library/scala/collection/Iterator.scala index 68cc35277..6c6f7387e 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 4453bca20..581518688 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) } }