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 9.0.5.0: uninitialized variables assigned to self as default method argument cause org.jruby.ir.operands.UndefinedValue #3703

Closed
PragTob opened this Issue Feb 28, 2016 · 4 comments

Comments

Projects
None yet
3 participants
@PragTob

PragTob commented Feb 28, 2016

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

@enebo

This comment has been minimized.

Show comment
Hide comment
@enebo

enebo Feb 28, 2016

Member

@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).

Member

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

@PragTob

This comment has been minimized.

Show comment
Hide comment
@PragTob

PragTob 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 9.0.5.0. So definitely a mistake, maybe after some rename or something...

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 9.0.5.0. So definitely a mistake, maybe after some rename or something...

@enebo

This comment has been minimized.

Show comment
Hide comment
@enebo

enebo Feb 29, 2016

Member

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

Member

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

@headius headius added this to the JRuby 9.1.0.0 milestone Mar 4, 2016

@headius

This comment has been minimized.

Show comment
Hide comment
@headius

headius Mar 4, 2016

Member

Fixed in c9e46b7.

Member

headius commented Mar 4, 2016

Fixed in c9e46b7.

@headius headius closed this Mar 4, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment