diff options
author | Lukas Rytz <lukas.rytz@epfl.ch> | 2009-02-10 09:32:05 +0000 |
---|---|---|
committer | Lukas Rytz <lukas.rytz@epfl.ch> | 2009-02-10 09:32:05 +0000 |
commit | b0bcd0a40d209e02cd8bbabedc5819f6ce8108ef (patch) | |
tree | 953a187b3c51ab55e0765560f41030f7a01f3ee7 /src | |
parent | 76009173e08545c346d4a66eb847a75120649ad2 (diff) | |
download | scala-b0bcd0a40d209e02cd8bbabedc5819f6ce8108ef.tar.gz scala-b0bcd0a40d209e02cd8bbabedc5819f6ce8108ef.tar.bz2 scala-b0bcd0a40d209e02cd8bbabedc5819f6ce8108ef.zip |
fix for #1691
Diffstat (limited to 'src')
-rw-r--r-- | src/library/scala/List.scala | 11 | ||||
-rw-r--r-- | src/library/scalax/collection/immutable/List.scala | 9 |
2 files changed, 16 insertions, 4 deletions
diff --git a/src/library/scala/List.scala b/src/library/scala/List.scala index e0e619e27e..eda39f9ec9 100644 --- a/src/library/scala/List.scala +++ b/src/library/scala/List.scala @@ -54,6 +54,8 @@ object List { * @return the sorted list of all integers in range [start;end). */ def range(start: Int, end: Int, step: Int): List[Int] = { + if (step == 0) + throw new IllegalArgumentException("step is zero") val b = new ListBuffer[Int] var i = start while ((step <= 0 || i < end) && (step >= 0 || i > end)) { @@ -71,7 +73,9 @@ object List { * * @param start the start value of the list * @param end the end value of the list - * @param step the increment function of the list, must be monotonically increasing or decreasing + * @param step the increment function of the list, which given <code>v<sub>n</sub></code>, + * computes <code>v<sub>n+1</sub></code>. Must be monotonically increasing + * or decreasing. * @return the sorted list of all integers in range [start;end). */ def range(start: Int, end: Int, step: Int => Int): List[Int] = { @@ -81,7 +85,10 @@ object List { var i = start while ((!up || i < end) && (!down || i > end)) { b += i - i += step(i) + val next = step(i) + if (i == next) + throw new IllegalArgumentException("the step function did not make any progress on "+ i) + i = next } b.toList } diff --git a/src/library/scalax/collection/immutable/List.scala b/src/library/scalax/collection/immutable/List.scala index bed0ab96f5..6851fb9769 100644 --- a/src/library/scalax/collection/immutable/List.scala +++ b/src/library/scalax/collection/immutable/List.scala @@ -589,7 +589,9 @@ object List extends SequenceFactory[List] { * @deprecated use @see iterate instead. * @param start the start value of the list * @param end the end value of the list - * @param step the increment function of the list, must be monotonically increasing or decreasing + * @param step the increment function of the list, which given <code>v<sub>n</sub></code>, + * computes <code>v<sub>n+1</sub></code>. Must be monotonically increasing + * or decreasing. * @return the sorted list of all integers in range [start;end). */ @deprecated def range(start: Int, end: Int, step: Int => Int): List[Int] = { @@ -599,7 +601,10 @@ object List extends SequenceFactory[List] { var i = start while ((!up || i < end) && (!down || i > end)) { b += i - i += step(i) + val next = step(i) + if (i == next) + throw new IllegalArgumentException("the step function did not make any progress on "+ i) + i = next } b.toList } |