<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;">
[Back after a few days off…]
<div><br>
</div>
<div>Indeed, Archie and I looked at this, and some other approaches, but in the end we went for the simpler approach. Simpler seemed better - alternatives just seemed to make the spec as obscure as the corner-cases we were trying to address! Anyway, apologies
 as I didn’t document this explicitly in the spec, which would have been helpful. I will do so, and perhaps add some other editorial notes to make it clearer what we have done.</div>
<div><br>
</div>
<div>Thanks,</div>
<div>Gavin<br id="lineBreakAtBeginningOfMessage">
<div><br>
<blockquote type="cite">
<div>On 30 May 2024, at 23:16, Archie Cobbs <archie.cobbs@gmail.com> wrote:</div>
<br class="Apple-interchange-newline">
<div>
<div dir="ltr">
<div dir="ltr">On Thu, May 30, 2024 at 5:08 AM Maurizio Cimadamore <<a href="mailto:maurizio.cimadamore@oracle.com" target="_blank">maurizio.cimadamore@oracle.com</a>> wrote:</div>
<div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<u></u>
<div>I note that this is effectively equivalent to say that the enclosing instance of the local class is the first enclosing instance that does not appear in a pre-construction context, correct? If we stated that, once and for all (in 8.1.3), couldn't we then
 avoid the need for having other special rules?</div>
</blockquote>
<br>
<div>(When trying to play with the JLS I still feel like a child wielding a weapon that's way too heavy for me)</div>
<div><br>
</div>
<div>At one point I took a stab at what §15.9.2 might say if you went down that route. It started with something like this:</div>
<div><br>
</div>
<div style="margin-left:40px">For any expression or class declaration E, define the first available enclosing instance of E, if any, as follows:<br>
    o If E occurs in a static context, then there is no first available enclosing instance of E.<br>
    o If E is a top-level class declaration, a static class declaration, or an interface declaration, then there is no first available enclosing instance of E.<br>
    o Otherwise, let O be the immediately enclosing class declaration of E.<br>
        o If E occurs in an early construction context of O, then the first available enclosing instance of E is the first available enclosing instance of O, if any.<br>
        o Otherwise, the first available enclosing instance of E is O's instance of this.</div>
</div>
<div><br>
</div>
<div>What's new here is that the definition is recursive, which seems to be inescapable if you want the rules to match the compiler's actual behavior.<br>
</div>
<div><br>
</div>
<div>But I agree with Dan that it's simpler to avoid all that and just say when you can and cannot reference the enclosing instances, i.e., remember we only need to specify the language here, not the compilation process.</div>
<div><br>
</div>
<div>This works for local and anonymous classes because the entire class, and therefore all references to an enclosing instance from the class, are either in a pre-construction context or not, and so there's never a difference between "the enclosing instance
 X exists" and "the expression X.this is legal".</div>
<div><br>
</div>
<div>Of course member classes are different - the enclosing instance is provided either explicitly or implicitly at construction time, and separate rules apply to handle that.<br>
</div>
<div><br>
</div>
<div>-Archie</div>
<div><br>
</div>
<span class="gmail_signature_prefix">-- </span><br>
<div dir="ltr" class="gmail_signature">Archie L. Cobbs<br>
</div>
</div>
</div>
</blockquote>
</div>
<br>
</div>
</body>
</html>