[External] : Re: RFR: 8194743: Compiler implementation for Statements before super() [v14]
Archie Cobbs
archie.cobbs at gmail.com
Mon Sep 25 19:45:55 UTC 2023
Hi Alex,
Thanks for the JEP comments, I will get with Gavin (who is managing the
drafts) on these.
On Mon, Sep 25, 2023 at 1:25 PM Alex Buckley <alex.buckley at oracle.com>
wrote:
>
> > Test.java:12: error: cannot reference this before supertype constructor
> > has been called
> > new Local(); // Legal or illegal?
> > ^
> > Test.java:10: error: calls to this() not allowed here
> > this(switch (0) { default -> throw new Exception(); });
> > ^
> > 3 errors
>
> Oops, yes. So, can you guarantee, in the JEP, that a non-static local
> class declared in the pre-construction context can never access
> enclosing state?
>
Reading that literally, no that's not guaranteed at all. You are allowed to
declare a (non-static) local class in a pre-construction context and then
instantiate it later, after super(), and access enclosing state.
What you can't do is instantiate it before super(). That's enforced by this
new line in §15.9.2:
> If the class instance creation expression occurs in the pre-construction
> context of class *K* (8.8.7.1
> <https://cr.openjdk.org/~gbierman/jep447/jep447-20230905/specs/statements-before-super-jls.html#jls-8.8.7.1>)
> and the immediately enclosing instance is also an instance of *K* then a
> compile-time error occurs.
>
Note this language applies to both local classes and member classes.
-Archie
--
Archie L. Cobbs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/compiler-dev/attachments/20230925/91e37e0b/attachment.htm>
More information about the compiler-dev
mailing list