Permalink
Browse files

Fixes SI-5328. Iterator.patched failed when from=0.

It turns out iterator.patched forgot to drop replacement values if they were at the beginning.
This is because the index was advancing before checking to see if replaced elements should be
dropped.   Moved this behavior to the beginning of next.
  • Loading branch information...
jsuereth committed May 9, 2012
1 parent da04d69 commit 84764949e299329e476824c96fb250f72506bacd
Showing with 10 additions and 1 deletion.
  1. +2 −1 src/library/scala/collection/Iterator.scala
  2. +3 −0 test/files/run/t5328.check
  3. +5 −0 test/files/run/t5328.scala
@@ -1079,11 +1079,12 @@ trait Iterator[+A] extends TraversableOnce[A] {
if (i < from) origElems.hasNext
else patchElems.hasNext || origElems.hasNext
def next(): B = {
+ // We have to do this *first* just in case from = 0.
+ if (i == from) origElems = origElems drop replaced
val result: B =
if (i < from || !patchElems.hasNext) origElems.next()
else patchElems.next()
i += 1
- if (i == from) origElems = origElems drop replaced
result
}
}
@@ -0,0 +1,3 @@
+2
+1,2,8
+1,8,3
@@ -0,0 +1,5 @@
+object Test extends App {
+ println(Vector(1).view.updated(0,2).toList mkString ",")
+ println(Seq(1,2,3).view.updated(2,8).toList mkString ",")
+ println(List(1,2,3).view.updated(1,8).toList mkString ",")
+}

0 comments on commit 8476494

Please sign in to comment.