Fix metaclass dispatch missing meta-metaclass methods#9446
Open
sampokuokkanen wants to merge 1 commit into
Open
Fix metaclass dispatch missing meta-metaclass methods#9446sampokuokkanen wants to merge 1 commit into
sampokuokkanen wants to merge 1 commit into
Conversation
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.
kares
reviewed
May 20, 2026
|
|
||
| klass.setMetaClass(superClass.getRealClass().metaClass); | ||
| // MRI: SET_METACLASS_OF(metaclass, ENSURE_EIGENCLASS(tmp)) | ||
| RubyClass effectiveSuper = superClass.isIncluded() ? superClass.getRealClass() : superClass; |
Member
There was a problem hiding this comment.
not sure I follow, is the included check really needed?
Contributor
Author
There was a problem hiding this comment.
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?
Contributor
Author
There was a problem hiding this comment.
Without it on boot:
java.lang.UnsupportedOperationException: An included class is only a wrapper for a module
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The sample code from #287 still errors on JRuby master:
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 usesingletonClass(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)