Skip to content

Commit 34f5c8f

Browse files
r6pRus Pandey
authored andcommitted
Fixing RangeError with code from 1.7 branch
With my previous commit, RangeError: bignum too big to convert into `long' was the result when running (0...2**64).max This commit ports handling for non-RubyFixnums from the 1.7.20 branch. Addresses, #3118
1 parent d79f665 commit 34f5c8f

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

core/src/main/java/org/jruby/RubyRange.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,11 @@ public IRubyObject max(ThreadContext context, Block block) {
659659
if (!(begin instanceof RubyInteger)) {
660660
throw context.runtime.newTypeError("cannot exclude end value with non Integer begin value");
661661
}
662-
rangeEnd = RubyFixnum.newFixnum(context.runtime, ((RubyInteger) end).getLongValue() - 1);
662+
if (end instanceof RubyFixnum) {
663+
rangeEnd = RubyFixnum.newFixnum(context.runtime, ((RubyFixnum)end).getLongValue() - 1);
664+
} else {
665+
rangeEnd = end.callMethod(context, "-", RubyFixnum.one(context.runtime));
666+
}
663667
} else {
664668
rangeEnd = end;
665669
}

test/mri/ruby/test_range.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def test_max
6969
assert_equal(2, (1..2).max)
7070
assert_equal(nil, (2..1).max)
7171
assert_equal(1, (1...2).max)
72+
assert_equal(18446744073709551615, (0...2**64).max)
7273

7374
assert_equal(2.0, (1.0..2.0).max)
7475
assert_equal(nil, (2.0..1.0).max)

0 commit comments

Comments
 (0)