[code-reflection] RFR: Issue errors when quotable constructs are found inside inner classes

Paul Sandoz psandoz at openjdk.org
Mon Jul 7 21:55:54 UTC 2025


On Mon, 7 Jul 2025 21:20:33 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

> > How feasible would it be to, eventually, do this?
> 
> To reply more directly to your question: we already have code to generate a model like that -- when we generate a model for quotable lambdas, we add extra parameters to the model to map enclosing `this` (where available) as well as any captured vars. We could do exactly the same for any method declared inside an inner class. In terms of code we can do it -- but this wouldn't model the semantics of the code eventually generated by javac (perhaps this become clearer when thinking about how such an approach would scale to model the _constructor_ of an inner class).

We are in effect extracting out something from its surrounding context and representing it as an isolated function whose parameters provide the context. Arguably modeling of instance methods is doing just that, as well quotable lambdas you point out, so we could do more of this and it would not look so out of place. (Similarly so for constructors when taking a functional view.) In this respect do we need to stick closely to the bytecode that javac generates?

Interpreting or generating bytecode and executing would require the user passing the contextual arguments.
(More broadly when generating bytecode and executing we have to also supply access control context and set things up appropriately. I seem to recall some difficulties around that, but the details escape me right now.)

-------------

PR Comment: https://git.openjdk.org/babylon/pull/486#issuecomment-3046616758


More information about the babylon-dev mailing list