Skip to content

JRuby 9.0.5.0: uninitialized variables assigned to self as default method argument cause org.jruby.ir.operands.UndefinedValue #3703

@PragTob

Description

@PragTob

Environment

tobi@happy ~/Desktop $ ruby -v
jruby 9.0.5.0 (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)
  a
end

p b

Results in:

tobi@happy ~/Desktop $ ruby fail.rb 
DEAD: marking instr dead!!
Unhandled Java exception: java.lang.RuntimeException: IR compiler/interpreter bug: org.jruby.ir.operands.UndefinedValue should not be used as a valid value during execution.
java.lang.RuntimeException: IR compiler/interpreter bug: org.jruby.ir.operands.UndefinedValue should not be used as a valid value during execution.
   undefinedOperation at org/jruby/ir/operands/UndefinedValue.java:57
           callMethod at org/jruby/ir/operands/UndefinedValue.java:63
            rbInspect at org/jruby/RubyBasicObject.java:1090
                    p at org/jruby/RubyKernel.java:465
                 call at org/jruby/internal/runtime/methods/JavaMethod.java:717
                 call at org/jruby/internal/runtime/methods/DynamicMethod.java:197
         cacheAndCall at org/jruby/runtime/callsite/CachingCallSite.java:313
                 call at org/jruby/runtime/callsite/CachingCallSite.java:163
                <top> at fail.rb:5
  invokeWithArguments at java/lang/invoke/MethodHandle.java:599
                 load at org/jruby/ir/Compiler.java:111
            runScript at org/jruby/Ruby.java:817
            runScript at org/jruby/Ruby.java:809
          runNormally at org/jruby/Ruby.java:747
          runFromMain at org/jruby/Ruby.java:569
        doRunFromMain at org/jruby/Main.java:415
          internalRun at org/jruby/Main.java:310
                  run at org/jruby/Main.java:239
                 main at org/jruby/Main.java:201

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
nil

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

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

Finishing

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 ;)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions