<div dir="ltr"><div>Hi Alex,</div><div><br></div><div>Thanks for the JEP comments, I will get with Gavin (who is managing the drafts) on these.<br></div><div dir="ltr"><br></div><div dir="ltr">On Mon, Sep 25, 2023 at 1:25 PM Alex Buckley <<a href="mailto:alex.buckley@oracle.com" target="_blank">alex.buckley@oracle.com</a>> wrote:<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">> Test.java:12: error: cannot reference this before supertype constructor <br>
> has been called<br>
>               new Local();  // Legal or illegal?<br>
>               ^<br>
> Test.java:10: error: calls to this() not allowed here<br>
>               this(switch (0) { default -> throw new Exception(); });<br>
>                   ^<br>
> 3 errors<br>
<br>
Oops, yes. So, can you guarantee, in the JEP, that a non-static local <br>
class declared in the pre-construction context can never access <br>
enclosing state?<br></blockquote><div><br></div><div>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.</div><div><br></div><div>What you can't do is instantiate it before super(). That's enforced by this new line in §15.9.2:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><p>If the class instance creation expression occurs in the
pre-construction context of class <em>K</em> (<a href="https://cr.openjdk.org/~gbierman/jep447/jep447-20230905/specs/statements-before-super-jls.html#jls-8.8.7.1">8.8.7.1</a>) and the immediately enclosing instance
is also an instance of <em>K</em> then a compile-time error occurs.</p></div></blockquote><div>Note this language applies to both local classes and member classes.</div><div><br></div><div>-Archie</div><div><br></div></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature">Archie L. Cobbs<br></div></div>