Skip to content

Commit

Permalink
Fixes SI-5328. Iterator.patched failed when from=0.
Browse files Browse the repository at this point in the history
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 8476494
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/library/scala/collection/Iterator.scala
Expand Up @@ -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
}
}
Expand Down
3 changes: 3 additions & 0 deletions test/files/run/t5328.check
@@ -0,0 +1,3 @@
2
1,2,8
1,8,3
5 changes: 5 additions & 0 deletions test/files/run/t5328.scala
@@ -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.