You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2021/04/12 06:04:16 UTC

[groovy] 10/26: GROOVY-9649: Fixed NumberRange.get not throwing at certain conditions

This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch groovy9649
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 6b5029ba4d44542df7958e805ec4dcd7f7159e1d
Author: Esko Toivonen <es...@tuni.fi>
AuthorDate: Tue Apr 6 17:59:44 2021 +0300

    GROOVY-9649: Fixed NumberRange.get not throwing at certain conditions
    
    With ranges like 0G<..<1G, the get method would erroneously return 1G
    instead of throwing an exception. This commit fixes that by directly
    incrementing the current value in the iterator instead of next() call.
---
 src/main/java/groovy/lang/NumberRange.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/main/java/groovy/lang/NumberRange.java b/src/main/java/groovy/lang/NumberRange.java
index 8a7c846..ece85c9 100644
--- a/src/main/java/groovy/lang/NumberRange.java
+++ b/src/main/java/groovy/lang/NumberRange.java
@@ -644,7 +644,7 @@ public class NumberRange extends AbstractList<Comparable> implements Range<Compa
                     // make the first fetch lazy too
                     next = isAscending ? range.getFrom() : range.getTo();
                     if (!range.inclusiveLeft) {
-                        next = next();
+                        next = isAscending ? increment(next, step) : decrement(next, step);
                     }
                 } else {
                     next = isAscending ? increment(next, step) : decrement(next, step);