diff options
-rw-r--r-- | src/library/scala/collection/immutable/Range.scala | 5 | ||||
-rw-r--r-- | test/files/run/bug3529.scala | 2 |
2 files changed, 6 insertions, 1 deletions
diff --git a/src/library/scala/collection/immutable/Range.scala b/src/library/scala/collection/immutable/Range.scala index 930b007389..68b50fd09f 100644 --- a/src/library/scala/collection/immutable/Range.scala +++ b/src/library/scala/collection/immutable/Range.scala @@ -120,7 +120,10 @@ class Range(val start: Int, val end: Int, val step: Int) extends IndexedSeq[Int] * @return a new range consisting of all the elements of this range except `n` first elements. */ final override def drop(n: Int): Range = - if (n >= length) copy(end + 1, end, step) + if (n >= length) { + if (step > 0) copy(end + 1, end, step) + else copy(end - 1, end, step) + } else copy(locationAfterN(n), end, step) /** Creates a new range containing all the elements of this range except the last one. diff --git a/test/files/run/bug3529.scala b/test/files/run/bug3529.scala index 4d83bcfa22..bb82424bf6 100644 --- a/test/files/run/bug3529.scala +++ b/test/files/run/bug3529.scala @@ -3,6 +3,8 @@ object Test { assert(1 to 10 drop 10 isEmpty) assert(1 until 10 drop 9 isEmpty) assert(1 to 10 by 2 drop 5 isEmpty) + assert(10 to 1 by -1 drop 10 isEmpty) + assert((10 to 1 by -1 drop 9) == Seq(1)) assert((1 to 10 drop 9) == Seq(10)) assert((1 until 10 drop 9) == Nil) |