Conversation
|
This is a WIP. The original issue appears to be fixed but my changes regressed some tests. I will request reviews once I'm satisfied with it. |
The Kernel versions of `autoload` use the caller's frame to determine the target module, where we were just detecting that `autoload` was called against Kernel and then defining the autoload on Object's singleton class. Other parts of autoload were not searching everything properly, or were not being triggered in the right places. * Fixes Kernel `autoload` and `autoload?` to use the caller's frame to determine the target module. * Fixes `autoload?` to check the constant tables for UNDEF before checking the autoload map, properly returning nil for autoload constants defined elsewhere without triggering autoload. * Fixes `const_defined?` to properly trigger autoload as in MRI's `rb_mod_const_defined`. * Adds overrides for autoload tables to IncludedModuleWrapper to aid the above searches. * Fixes an assertion in test/jruby/test_autoload that did not match MRI behavior. Fixes jruby#5466.
49504d7 to
051ad43
Compare
|
I think I've got everything in place. A number of spec tags and a few test excludes have been removed. |
| static RubyModule getModuleForAutoload(ThreadContext context, IRubyObject recv) { | ||
| RubyModule target = context.getCurrentStaticScope().getModule(); | ||
|
|
||
| while (target != null && (target.isSingleton() || target.isIncluded())) { |
There was a problem hiding this comment.
@headius So if I autoload in a module which has been included then it migrates to where that was included? If that module is included in two places then does only the first one fire and get stuck somewhere else? This easily may be the semantics....
There was a problem hiding this comment.
Yes that appears to be the semantics. In MRI this logic is rb_class_real, our "getRealClass" but that method lives on RubyClass and not RubyModule.
|
This should also get fixed in this PR: https://bugs.ruby-lang.org/issues/14469 I'm tagging a couple MRI tests related to that fix. |
The Kernel versions of
autoloaduse the caller's frame todetermine the target module, where we were just detecting that
autoloadwas called against Kernel and then defining theautoload on Object's singleton class.
test/jruby/test_autoload.rb has also been modified to match Ruby
2.5 behavior.
Fixes #5466.