summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Suereth <joshua.suereth@gmail.com>2012-05-08 21:53:25 -0400
committerJosh Suereth <joshua.suereth@gmail.com>2012-05-08 21:53:25 -0400
commit84764949e299329e476824c96fb250f72506bacd (patch)
tree86c9365cf1a95ad293e87ef5c731e169238ba477
parentda04d691c455aa3f3391bdbd9bac7fb59f29cedf (diff)
downloadscala-84764949e299329e476824c96fb250f72506bacd.tar.gz
scala-84764949e299329e476824c96fb250f72506bacd.tar.bz2
scala-84764949e299329e476824c96fb250f72506bacd.zip
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.
-rw-r--r--src/library/scala/collection/Iterator.scala3
-rw-r--r--test/files/run/t5328.check3
-rw-r--r--test/files/run/t5328.scala5
3 files changed, 10 insertions, 1 deletions
diff --git a/src/library/scala/collection/Iterator.scala b/src/library/scala/collection/Iterator.scala
index e9a7906527..7d5cd9989c 100644
--- a/src/library/scala/collection/Iterator.scala
+++ b/src/library/scala/collection/Iterator.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
}
}
diff --git a/test/files/run/t5328.check b/test/files/run/t5328.check
new file mode 100644
index 0000000000..77a43968c5
--- /dev/null
+++ b/test/files/run/t5328.check
@@ -0,0 +1,3 @@
+2
+1,2,8
+1,8,3
diff --git a/test/files/run/t5328.scala b/test/files/run/t5328.scala
new file mode 100644
index 0000000000..12adf45b84
--- /dev/null
+++ b/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 ",")
+}