Skip to content

Commit 4c429d9

Browse files
committed
Floor for NewVectorIterator.slice limit
Fixes scala/bug#12823 Adds a floor of 0 to the limit parameter of NewVectorIterator.slice. This matches the base behavior of Iterator.slice and Vector.slice.
1 parent c3b683c commit 4c429d9

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

library/src/scala/collection/immutable/Vector.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2389,12 +2389,14 @@ private final class NewVectorIterator[A](v: Vector[A], private[this] var totalLe
23892389
}
23902390

23912391
override def slice(from: Int, until: Int): Iterator[A] = {
2392-
val _until =
2392+
val _until = mmax(until, 0)
2393+
2394+
val n =
23932395
if(from > 0) {
23942396
drop(from)
2395-
until - from
2396-
} else until
2397-
take(_until)
2397+
_until - from
2398+
} else _until
2399+
take(n)
23982400
}
23992401

24002402
override def copyToArray[B >: A](xs: Array[B], start: Int, len: Int): Int = {

0 commit comments

Comments
 (0)