Skip to content

autoload + private_constant do not play well together #8994

@enebo

Description

@enebo

Marking an autoload constant as a private_constant makes them seem uninitialized. Test case:

test.rb:

class Foo
  autoload :Bar, 'bar'

  private_constant :Bar

  def self.bar
    Bar
  end
end

p Foo.bar

bar.rb:

puts "loading bar"
Bar = "fubar"
jruby -I. test.rb
NameError: uninitialized constant Foo::Bar
  const_missing at org/jruby/RubyModule.java:4867
            bar at const2.rb:8
         <main> at const2.rb:12

If it runs it should show:

loading bar
"fubar"

What is interesting is there is no "loading bar" print so I will guess that marking Bar private is preventing the autoload from firing.

Note that this does not affect JRuby 9.4. Only 10.0.x

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions