summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
authorRex Kerr <ichoran@gmail.com>2014-02-13 17:47:27 -0800
committerRex Kerr <ichoran@gmail.com>2014-02-13 17:47:27 -0800
commitd3a302b022adc5eaeb1fcbdffaffd5fd438726e0 (patch)
tree8f11e757d17d29e13e106bd7426591c8813ed610 /src/library
parentc83e01d47d941265fa5415c0f29a884c904fdfa0 (diff)
downloadscala-d3a302b022adc5eaeb1fcbdffaffd5fd438726e0.tar.gz
scala-d3a302b022adc5eaeb1fcbdffaffd5fd438726e0.tar.bz2
scala-d3a302b022adc5eaeb1fcbdffaffd5fd438726e0.zip
SI-6632 ListBuffer's updated accepts negative positions
Changed the behavior in SeqLike.updated (which would silently accept negatives and throw on empty.tail) to throw IndexOutOfBoundException. Updated tests to verify the behavior in ListBuffer. Everything else SeqLike will come along for the ride.
Diffstat (limited to 'src/library')
-rw-r--r--src/library/scala/collection/SeqLike.scala5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/library/scala/collection/SeqLike.scala b/src/library/scala/collection/SeqLike.scala
index 960c277f67..fdfb1f2efc 100644
--- a/src/library/scala/collection/SeqLike.scala
+++ b/src/library/scala/collection/SeqLike.scala
@@ -509,11 +509,14 @@ trait SeqLike[+A, +Repr] extends Any with IterableLike[A, Repr] with GenSeqLike[
}
def updated[B >: A, That](index: Int, elem: B)(implicit bf: CanBuildFrom[Repr, B, That]): That = {
+ if (index < 0) throw new IndexOutOfBoundsException(index.toString)
val b = bf(repr)
val (prefix, rest) = this.splitAt(index)
+ val restColl = toCollection(rest)
+ if (restColl.isEmpty) throw new IndexOutOfBoundsException(index.toString)
b ++= toCollection(prefix)
b += elem
- b ++= toCollection(rest).view.tail
+ b ++= restColl.view.tail
b.result()
}