Skip to content

Fix metaclass dispatch missing meta-metaclass methods#9446

Open
sampokuokkanen wants to merge 1 commit into
jruby:masterfrom
sampokuokkanen:meta-eigenclass-fix
Open

Fix metaclass dispatch missing meta-metaclass methods#9446
sampokuokkanen wants to merge 1 commit into
jruby:masterfrom
sampokuokkanen:meta-eigenclass-fix

Conversation

@sampokuokkanen
Copy link
Copy Markdown
Contributor

The sample code from #287 still errors on JRuby master:

class Foo
  class << self
    class << self
      def foo; end
    end
  end
end
class Bar < Foo; end
Bar.singleton_class.foo
(irb):11:in 'evaluate': undefined method 'foo' for class #<Class:Bar> (NoMethodError)

This is because currently in master the code is stripping away singleton classes and not creating a singleton class in case one is missing.

So skip the wrapper with isIncluded() and use singletonClass(context) to get the correct eigenclass.
This lets us drop spec/tags/ruby/language/metaclass_tags.txt, but the MRI tests are still failing since they go one step further (meta-meta-meta tier, blows up on line 160), and with meta-meta classes there is still an issue there with how they are handled (see MetaClass.java:109, can't just fix it as it leads to a stack overflow with the same shape of fix as I did on line 542)

Set new singleton's metaClass to its parent's eigenclass instead of
the parent's regular metaclass. Matches MRI's ENSURE_EIGENCLASS in
class.c make_metaclass.

klass.setMetaClass(superClass.getRealClass().metaClass);
// MRI: SET_METACLASS_OF(metaclass, ENSURE_EIGENCLASS(tmp))
RubyClass effectiveSuper = superClass.isIncluded() ? superClass.getRealClass() : superClass;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure I follow, is the included check really needed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While writing this I first thought we wouldn't need the check, but the code didn't work without it. Turns out we can get a BlankSlateWrapper here instead of the actual module (from JavaPackage.createJavaPackageClass).

Should I add // unwrap IncludedModuleWrapper (e.g. BlankSlateWrapper from JavaPackage) as an inline comment?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without it on boot:
java.lang.UnsupportedOperationException: An included class is only a wrapper for a module

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants