Skip to content
This repository was archived by the owner on Feb 23, 2018. It is now read-only.

Commit 43a6cd5

Browse files
author
extempore
committed
Fixed up the regression I slipped in with slice. Thanks to prokopec
for pointing me toward the problem. No review. git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@24436 5e8d7ff9-d8ef-0310-90f0-a4852d11357a
1 parent a4462ca commit 43a6cd5

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

src/library/scala/collection/SeqViewLike.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,11 @@ trait SeqViewLike[+A,
194194
val thatElem = _thatElem
195195
} with ZippedAll[A1, B]
196196
protected def newReversed: Transformed[A] = new Reversed { }
197-
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]
197+
protected def newPatched[B >: A](_from: Int, _patch: Seq[B], _replaced: Int): Transformed[B] = new {
198+
val from = _from
199+
val patch = _patch
200+
val replaced = _replaced
201+
} with Patched[B]
198202
protected def newPrepended[B >: A](elem: B): Transformed[B] = new { protected[this] val fst = elem } with Prepended[B]
199203

200204
override def reverse: This = newReversed.asInstanceOf[This]

src/library/scala/collection/generic/SliceInterval.scala

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ package generic
1111

1212
/** A container for the endpoints of a collection slice.
1313
* The constructor is private to enforce the invariants:
14-
* from >= 0 and until >= 0.
14+
* from >= 0, until >= 0, from <= until.
1515
*/
1616
private[collection] class SliceInterval private (val from: Int, val until: Int) {
1717
// The width of this slice from end to end. This is the
1818
// maximum size of the collection slice, but the collection
19-
// need not have this many (or any) elements.
19+
// need not have this many (or any) elements. Since
20+
// from <= until is a constructor invariant, we don't have to
21+
// check for negative values.
2022
def width = until - from
2123

2224
/** Returns a new SliceInterval with endpoints calculated in
@@ -41,5 +43,11 @@ private[collection] class SliceInterval private (val from: Int, val until: Int)
4143
}
4244

4345
object SliceInterval {
44-
def apply(from: Int, until: Int) = new SliceInterval(from max 0, until max 0)
46+
def apply(from: Int, until: Int) = {
47+
val lo = from max 0
48+
val hi = until max 0
49+
50+
if (hi <= lo) new SliceInterval(lo, lo)
51+
else new SliceInterval(lo, hi)
52+
}
4553
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
object Test {
2+
def f = collection.mutable.ArrayBuffer(1, 2, 3, 4, 5, 6, 7, 8)
3+
def g = f.patch(4, List(1, 2), 10)
4+
5+
def main(args: Array[String]): Unit = {
6+
assert(g.size == 6)
7+
}
8+
}

0 commit comments

Comments
 (0)