Sitelet https://github.com/jruby/jruby/issues/5466
Skip to content

Weird Kernel.autoload behavior #5466

Description

@MaxLap

Environment

Provide at least:

  • JRuby version (jruby -v) and command line (flags, JRUBY_OPTS, etc)
    jruby 9.2.5.0-SNAPSHOT (2.5.0) 2018-11-22 93f0df3 OpenJDK 64-Bit Server VM 25.181-b13 on 1.8.0_181-8u181-b13-1ubuntu0.16.04.1-b13 +jit [linux-x86_64]
  • Operating system and platform (e.g. uname -a)
    Ubuntu 16.04
    Linux max-u1604 4.4.0-139-generic #165-Ubuntu SMP Wed Oct 24 10:58:50 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

Problem

I expect Kernel.autoload :Hi, 'somefile' to do something useful. Right now, the only way found to trigger that autoload is do call .singleton_class::Hi on any class (It can be String, Object, etc). I really doubt there is any usecase for this.

In MRI, Kernel#autoload and Kernel.autoload always use the Module.nested of the calling context.

In JRuby, Kernel#autoload uses the object of the calling code. (This difference only shows up if the autoload call is in an instance method of a module, which is included in a class, and the method is called from an instance of the class.. Not something to worry about)

However, JRuby seems to special case Kernel.autoload weirdly. Looking at the code:

// special behavior if calling Kernel.autoload directly
module = runtime.getObject().getSingletonClass();

Ideally, Kernel.autoload would behave the same as calling Kernel#autoload.

Activity

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

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