Skip to content

Regression: Class variables in top level methods broken compared to MRI & 9.3 #7656

@byteit101

Description

@byteit101

Environment Information

JRuby 9.4.0.0

Expected Behavior

~/code/jrubyfx(master ✗) irb
3.0.0 :001 > module Kernel; def testk(i=nil); if i.nil?; return @@foob; else @@foob = i; end; end; end
 => :testk 
3.0.0 :002 > testk 9
 => 9 
3.0.0 :003 > testk
 => 9 
3.0.0 :004 > 

Actual Behavior

~/code/jrubyfx(master ✗) irb                  
jruby-9.4.0.0 :001 > module Kernel; def testk(i=nil); if i.nil?; return @@foob; else @@foob = i; end; end; end
 => :testk 
jruby-9.4.0.0 :002 > testk 9
(irb):1:in `testk': class variable access from toplevel (RuntimeError)
	from (irb):2:in `evaluate'
	from org/jruby/RubyKernel.java:1143:in `eval'
	from org/jruby/RubyKernel.java:1586:in `loop'
	from org/jruby/RubyKernel.java:1292:in `catch'
	from org/jruby/RubyKernel.java:1292:in `catch'
	from /home/byteit101/.rvm/rubies/jruby-9.4.0.0/lib/ruby/gems/shared/gems/irb-1.4.1/exe/irb:11:in `<main>'
	from org/jruby/RubyKernel.java:1091:in `load'
	from /home/byteit101/.rvm/rubies/jruby-9.4.0.0/bin/irb:23:in `<main>'
	from org/jruby/RubyKernel.java:1143:in `eval'
	from /home/byteit101/.rvm/gems/jruby-9.4.0.0/bin/jruby_executable_hooks:22:in `<main>'
jruby-9.4.0.0 :003 > 

I noticed this because it affects JRubyFX's Kernel extensions. A workaround seems to be to replace cvar usage with Kernel.class_variable_get(:@@...)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions