Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JRuby uninitialized variables assigned to self as default method argument cause #3703

PragTob opened this issue Feb 28, 2016 · 4 comments


Copy link

PragTob commented Feb 28, 2016


tobi@happy ~/Desktop $ ruby -v
jruby (2.2.3) 2016-01-26 7bee00d OpenJDK 64-Bit Server VM 24.95-b01 on 1.7.0_95-b00 +jit [linux-amd64]
tobi@happy ~/Desktop $ uname -a
Linux happy 3.19.0-32-generic #37~14.04.1-Ubuntu SMP Thu Oct 22 09:41:40 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
tobi@happy ~/Desktop $ java -version
java version "1.7.0_95"
OpenJDK Runtime Environment (IcedTea 2.6.4) (7u95-2.6.4-0ubuntu0.14.04.1)
OpenJDK 64-Bit Server VM (build 24.95-b01, mixed mode)

Actual Behavior

Sample script:

def b(a = a)

p b

Results in:

tobi@happy ~/Desktop $ ruby fail.rb 
DEAD: marking instr dead!!
Unhandled Java exception: java.lang.RuntimeException: IR compiler/interpreter bug: should not be used as a valid value during execution.
java.lang.RuntimeException: IR compiler/interpreter bug: should not be used as a valid value during execution.
   undefinedOperation at org/jruby/ir/operands/
           callMethod at org/jruby/ir/operands/
            rbInspect at org/jruby/
                    p at org/jruby/
                 call at org/jruby/internal/runtime/methods/
                 call at org/jruby/internal/runtime/methods/
         cacheAndCall at org/jruby/runtime/callsite/
                 call at org/jruby/runtime/callsite/
                <top> at fail.rb:5
  invokeWithArguments at java/lang/invoke/
                 load at org/jruby/ir/
            runScript at org/jruby/
            runScript at org/jruby/
          runNormally at org/jruby/
          runFromMain at org/jruby/
        doRunFromMain at org/jruby/
          internalRun at org/jruby/
                  run at org/jruby/
                 main at org/jruby/

It is possible to cary the undefined value quite a bit further (in my case setting it as a value for the stub - fix commit) - the error was raised quite a way further when the stubbed value was first called. That's also why in the sample I do p b, just b doesn't cause the error.

Expected Behavior

Probably what CRuby does:

tobi@happy ~/Desktop $ rvm use 2.2.4 # does the same on 2.3
Using /home/tobi/.rvm/gems/ruby-2.2.4
tobi@happy ~/Desktop $ ruby fail.rb 
fail.rb:1: warning: circular argument reference - a

This is also somewhat backwards incompatible, as JRuby reacts differently:

tobi@happy ~/Desktop $ rvm use jruby-
Using /home/tobi/.rvm/gems/jruby-
tobi@happy ~/Desktop $ ruby fail.rb 
NameError: undefined local variable or method `a' for main:Object
  <top> at fail.rb:5


Might be related to #3094

Also sort of sad that I didn't do a lot on shoes these past months, otherwise I'd caught this earlier, potentially already on head :| But well it's not too important, as it is effectively rather broken code ;)

Copy link

enebo commented Feb 28, 2016

@PragTob can I ask why you did a = a as a pattern? I sort of knew this was broken but did not think anyone would ever use it (so it was not much of a priority).

Copy link

PragTob commented Feb 28, 2016

@enebo classic programming error :D It was some old part of the code I just got the failing tests after upgrading to So definitely a mistake, maybe after some rename or something...

Copy link

enebo commented Feb 29, 2016

@PragTob ah thanks for the explanation. I could not figure out an idiom which would make this useful but you never know with Ruby :)

Copy link

headius commented Mar 4, 2016

Fixed in c9e46b7.

@headius headius closed this as completed Mar 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

3 participants