From 9f2083b88e003a3f2a641460244c44b0f1f06821 Mon Sep 17 00:00:00 2001 From: Rex Kerr Date: Sat, 6 Dec 2014 14:18:24 -0800 Subject: 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.) --- src/library/scala/collection/SeqViewLike.scala | 2 +- src/library/scala/collection/mutable/IndexedSeqView.scala | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/library') diff --git a/src/library/scala/collection/SeqViewLike.scala b/src/library/scala/collection/SeqViewLike.scala index ef6d2272cb..59e0e73e89 100644 --- a/src/library/scala/collection/SeqViewLike.scala +++ b/src/library/scala/collection/SeqViewLike.scala @@ -55,7 +55,7 @@ trait SeqViewLike[+A, trait Sliced extends super.Sliced with Transformed[A] { def length = iterator.size def apply(idx: Int): A = - if (idx + from < until) self.apply(idx + from) + if (idx >= 0 && idx + from < until) self.apply(idx + from) else throw new IndexOutOfBoundsException(idx.toString) override def foreach[U](f: A => U) = iterator foreach f diff --git a/src/library/scala/collection/mutable/IndexedSeqView.scala b/src/library/scala/collection/mutable/IndexedSeqView.scala index 31a4749960..7acdeeff18 100644 --- a/src/library/scala/collection/mutable/IndexedSeqView.scala +++ b/src/library/scala/collection/mutable/IndexedSeqView.scala @@ -50,7 +50,7 @@ self => trait Sliced extends super.Sliced with Transformed[A] { override def length = endpoints.width def update(idx: Int, elem: A) = - if (idx + from < until) self.update(idx + from, elem) + if (idx >= 0 && idx + from < until) self.update(idx + from, elem) else throw new IndexOutOfBoundsException(idx.toString) } -- cgit v1.2.3