Fix prepended module initialize not called for Ruby classes rooted in a Java superclass#9322
Merged
headius merged 2 commits intojruby:jruby-10.0from Mar 23, 2026
Merged
Conversation
… a Java superclass When a module M is prepended to a Ruby class E that subclasses a Java class, the split constructor protocol only saw M's initialize (the effective method after prepend) and never invoked E's own initialize, producing [:d, :c] instead of the correct [:m, :e, :d, :c]. Root causes: - tryInstall used clazz.searchMethod which found M's initialize (via prepend hierarchy) instead of E's, so oldInit was wrong - splitInitialized had no way to express two Ruby initializes at the same reified-class level (M wrapping E), only a flat isLateral branch - SplitCtorData lacked a clazz field so finishInitialize used getMetaClass() as the defining module, causing incorrect method lookup Fix: - tryInstall now uses clazz.getMethodLocation().searchMethod to capture E's own initialize as oldInit - Add findIncludedPrependedModule helper to detect when the found method lives in an included prepend-wrapper for the base class - Add isPrependedJavaCtorWrapper to identify this specific structural case - In splitInitialized, handle the prepend-wrapper case by splitting M first, recursing into the prepend-wrapper's superclass for E's split, then chaining the two SplitCtorData via a new nested field - finishInitialize recurses through nested first, ensuring M->E->D->C order - Add clazz field to SplitCtorData so finishInitialize uses the correct defining module for direct (no-state) calls - Fix isClassOrIncludedPrependedModule to use getDelegate() comparisons
bed8c79 to
2f1f0b6
Compare
kares
reviewed
Mar 22, 2026
Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
headius
approved these changes
Mar 23, 2026
Member
headius
left a comment
There was a problem hiding this comment.
Looks logical to me. The operative change seems to be using getMethodLocation so that prepends are handled correctly.
Member
|
@jimtng Thank you for looking into this issue! |
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.
Fix #9321
When a module M is prepended to a Ruby class E that subclasses a Java class, the split constructor protocol only saw M's initialize (the effective method after prepend) and never invoked E's own initialize, producing [:d, :c] instead of the correct [:m, :e, :d, :c].
Root causes:
Fix: