Skip to content

Commit 9f2083b

Browse files
committed
SI-8950 SeqView and StreamView allow indexing out of a slice
Added `idx >= 0` tests for `SeqViewLike#Sliced` `apply` and `mutable.IndexedSeqViewLike#Sliced` `unapply`. Now you get `IndexOutOfBoundsException`s as you should. No tests; this was found by collections-laws and will be tested by them. (Exact variants in bug report were tested in the REPL.)
1 parent 8810489 commit 9f2083b

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/library/scala/collection/SeqViewLike.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ trait SeqViewLike[+A,
5555
trait Sliced extends super.Sliced with Transformed[A] {
5656
def length = iterator.size
5757
def apply(idx: Int): A =
58-
if (idx + from < until) self.apply(idx + from)
58+
if (idx >= 0 && idx + from < until) self.apply(idx + from)
5959
else throw new IndexOutOfBoundsException(idx.toString)
6060

6161
override def foreach[U](f: A => U) = iterator foreach f

src/library/scala/collection/mutable/IndexedSeqView.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ self =>
5050
trait Sliced extends super.Sliced with Transformed[A] {
5151
override def length = endpoints.width
5252
def update(idx: Int, elem: A) =
53-
if (idx + from < until) self.update(idx + from, elem)
53+
if (idx >= 0 && idx + from < until) self.update(idx + from, elem)
5454
else throw new IndexOutOfBoundsException(idx.toString)
5555
}
5656

0 commit comments

Comments
 (0)