diff options
author | Adriaan Moors <adriaan.moors@typesafe.com> | 2014-02-14 13:23:44 -0800 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@typesafe.com> | 2014-02-14 13:23:44 -0800 |
commit | d62ceb88278bbe8317e8dcce6fb8515cae64e2b1 (patch) | |
tree | 9ebf30b69000bd659452a79fc1d36e2876455dfc /src/library | |
parent | d227a89363886635969f4a7725303c6b65b0914b (diff) | |
parent | d3a302b022adc5eaeb1fcbdffaffd5fd438726e0 (diff) | |
download | scala-d62ceb88278bbe8317e8dcce6fb8515cae64e2b1.tar.gz scala-d62ceb88278bbe8317e8dcce6fb8515cae64e2b1.tar.bz2 scala-d62ceb88278bbe8317e8dcce6fb8515cae64e2b1.zip |
Merge pull request #3530 from Ichoran/issue/6632
SI-6632 ListBuffer's updated accepts negative positions
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/scala/collection/SeqLike.scala | 5 |
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() } |