Also retain runtime-invokable inline methods when they are indirectly overriden - #26644
Open
jchyb wants to merge 2 commits into
Open
Also retain runtime-invokable inline methods when they are indirectly overriden#26644jchyb wants to merge 2 commits into
jchyb wants to merge 2 commits into
Conversation
jchyb
force-pushed
the
fix-i25206-indirect-inline-override
branch
from
July 29, 2026 22:07
c673c6d to
0e45f9e
Compare
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.
Fixes #25206
As described in the reference (and in the Inlining paper), we allow inline methods to override abstract ones (treating those inline methods as effectively final). we do that by checking if the inline method overrides something from the perspective of it's own class, creating a $retainedBody method that holds the inlined implementation. This $retainedBody then replaces the inline method in erasure (since inline methods are usually completely erased there). The issue arises with cases where we indirectly override something, like in the issue reproducer:
Here, the
switchfromSettingsoverridesswitchfromInner, where we don't create a retainedBody in Settings, thus completely erasing switch, causing a runtime error.We fix this by separately recognizing this case and adding a similar
switch$indirectRetainedBodymethod inOuter, later replaced with the actualswitchin erasure. So we effectively copy the implementation into the class where the issue can appear (similarly to how inline traits work in #26156, where I got the idea from). We cannot retroactively put it in Settings, as under separate compilation, by the time we compile Outer, Settings might have had been already compiled to a classfile, so there is no other solution possible here.Some additional considerations:
$indirectRetainedBodydefinition procedure purposefully similar to $retainedBody, to avoid new issues - this is also why it's in Typer, theoretically it could have been in any phase before Inlining, but then we would have$indirectRetainedBodyand$retainedBodyinlined in different phases, which seems like a recipe for confusion.only Outer gets the runtime-invoked inlined switch copy.
Have you relied on LLM-based tools in this contribution?
Yes, mostly for refactors (move X into Y phase and querying about the compiler), and I checked the output by manually reading through the code and confirming it matched what I wanted.
How was the solution tested?
New automated tests (including the issue's reproducer, if applicable)