diff options
author | Paul Phillips <paulp@improving.org> | 2010-06-04 05:16:08 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2010-06-04 05:16:08 +0000 |
commit | 245ec93fb132d2597a05d7ae9e081cd1adf356a3 (patch) | |
tree | d95b29ec9e3ee9a9b99cdba054bfe4f0e9d70b92 | |
parent | ebb6c4a2d9d882ea258ac64afb5235041f4f40ab (diff) | |
download | scala-245ec93fb132d2597a05d7ae9e081cd1adf356a3.tar.gz scala-245ec93fb132d2597a05d7ae9e081cd1adf356a3.tar.bz2 scala-245ec93fb132d2597a05d7ae9e081cd1adf356a3.zip |
Burned by a last minute adjustment, I lost the ...
Burned by a last minute adjustment, I lost the downward counting
direction. It is a seriously fiddly process to adjust Range and I don't
recommend it to anyone. Closes #3529 over again. Review by prokopec.
-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) |