Bignum#[] returns an incorrect result when Bignum is given
----------------------------------------------------------

                 Key: JRUBY-6049
                 URL: https://jira.codehaus.org/browse/JRUBY-6049
             Project: JRuby
          Issue Type: Bug
          Components: Core Classes/Modules
            Reporter: Yusuke Endoh


$ bin/jruby -e 'p (-1<<100)[(1<<100)]'
0

$ ruby -e 'p (-1<<100)[(1<<100)]'
1


$ bin/jruby -e 'p ((1<<100) + 3)[(1<<100).coerce(1).first]'
0

$ ruby -e 'p ((1<<100) + 3)[(1<<100).coerce(1).first]'
1


diff --git a/src/org/jruby/RubyBignum.java b/src/org/jruby/RubyBignum.java
index b42a349..cd8d9d7 100644
--- a/src/org/jruby/RubyBignum.java
+++ b/src/org/jruby/RubyBignum.java
@@ -787,8 +787,9 @@ public class RubyBignum extends RubyInteger {
      */
     @JRubyMethod(name = "[]", required = 1)
     public RubyFixnum op_aref(IRubyObject other) {
-        if (other instanceof RubyBignum) {
-            if (((RubyBignum) other).value.signum() >= 0 || value.signum() == 
-1) {
+        if (other instanceof RubyBignum && (other = bignorm(getRuntime(), 
((RubyBignum) other).value)) instanceof RubyBignum) {
+
+            if ((((RubyBignum) other).value.signum() >= 0) != (value.signum() 
== -1)) {
                 return RubyFixnum.zero(getRuntime());
             }
             return RubyFixnum.one(getRuntime());

-- 
Yusuke Endoh <m...@tsg.ne.jp>

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to