From e86934018bf3078a1a9751c16b95621a04575707 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Sat, 12 Mar 2011 01:59:46 +0000 Subject: Fixed up the regression I slipped in with slice. for pointing me toward the problem. No review. --- src/library/scala/collection/SeqViewLike.scala | 6 +++++- src/library/scala/collection/generic/SliceInterval.scala | 14 +++++++++++--- test/files/run/patch-boundary.scala | 8 ++++++++ 3 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 test/files/run/patch-boundary.scala diff --git a/src/library/scala/collection/SeqViewLike.scala b/src/library/scala/collection/SeqViewLike.scala index f5a61ec350..2bd8e29b65 100644 --- a/src/library/scala/collection/SeqViewLike.scala +++ b/src/library/scala/collection/SeqViewLike.scala @@ -194,7 +194,11 @@ trait SeqViewLike[+A, val thatElem = _thatElem } with ZippedAll[A1, B] protected def newReversed: Transformed[A] = new Reversed { } - protected def newPatched[B >: A](_from: Int, _patch: Seq[B], _replaced: Int): Transformed[B] = new { val from = _from; val patch = _patch; val replaced = _replaced } with Patched[B] + protected def newPatched[B >: A](_from: Int, _patch: Seq[B], _replaced: Int): Transformed[B] = new { + val from = _from + val patch = _patch + val replaced = _replaced + } with Patched[B] protected def newPrepended[B >: A](elem: B): Transformed[B] = new { protected[this] val fst = elem } with Prepended[B] override def reverse: This = newReversed.asInstanceOf[This] diff --git a/src/library/scala/collection/generic/SliceInterval.scala b/src/library/scala/collection/generic/SliceInterval.scala index 5c980c7677..56033ca8d8 100644 --- a/src/library/scala/collection/generic/SliceInterval.scala +++ b/src/library/scala/collection/generic/SliceInterval.scala @@ -11,12 +11,14 @@ package generic /** A container for the endpoints of a collection slice. * The constructor is private to enforce the invariants: - * from >= 0 and until >= 0. + * from >= 0, until >= 0, from <= until. */ private[collection] class SliceInterval private (val from: Int, val until: Int) { // The width of this slice from end to end. This is the // maximum size of the collection slice, but the collection - // need not have this many (or any) elements. + // need not have this many (or any) elements. Since + // from <= until is a constructor invariant, we don't have to + // check for negative values. def width = until - from /** Returns a new SliceInterval with endpoints calculated in @@ -41,5 +43,11 @@ private[collection] class SliceInterval private (val from: Int, val until: Int) } object SliceInterval { - def apply(from: Int, until: Int) = new SliceInterval(from max 0, until max 0) + def apply(from: Int, until: Int) = { + val lo = from max 0 + val hi = until max 0 + + if (hi <= lo) new SliceInterval(lo, lo) + else new SliceInterval(lo, hi) + } } diff --git a/test/files/run/patch-boundary.scala b/test/files/run/patch-boundary.scala new file mode 100644 index 0000000000..ed1a0e9fc1 --- /dev/null +++ b/test/files/run/patch-boundary.scala @@ -0,0 +1,8 @@ +object Test { + def f = collection.mutable.ArrayBuffer(1, 2, 3, 4, 5, 6, 7, 8) + def g = f.patch(4, List(1, 2), 10) + + def main(args: Array[String]): Unit = { + assert(g.size == 6) + } +} -- cgit v1.2.3