<div dir="ltr"><div dir="ltr">On Mon, Jun 10, 2024 at 3:37 PM Maurizio Cimadamore <<a href="mailto:maurizio.cimadamore@oracle.com">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">But I suspect what you meant (but you didn't say) is</blockquote><div><br></div><div>Thanks - you read my mind better than I do :) My example didn't really prove anything.<br></div><div><br></div><div>Here's a better one. Attr.java line 617 <a href="https://github.com/openjdk/jdk/blob/master/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java#L617">refers to the instance field Attr.chk</a> from anonymous inner class <span style="font-family:monospace">RecoveryInfo.Check.NestedCheckContext$1</span> which is declared in a <span style="font-family:monospace">super()</span> parameter in the <span style="font-family:monospace">RecoveryInfo()</span> constructor.</div><div><br></div><div><div>If that anonymous inner class had no outer instances, then wouldn't it be unable to access <span style="font-family:monospace">Attr.this.chk</span> ? <br></div><div><br></div></div><div>In summarized form this example similar to others I've been showing:<br></div><div><br></div><div style="margin-left:40px"><span style="font-family:monospace">class Outer</span></div><div style="margin-left:40px"><span style="font-family:monospace">    int x;</span></div><div style="margin-left:40px"><span style="font-family:monospace">    class Inner extends Foo {</span></div><div style="margin-left:40px"><span style="font-family:monospace">        Inner() {</span></div><div style="margin-left:40px"><span style="font-family:monospace">            super(new Bar() {<br></span></div><div style="margin-left:40px"><span style="font-family:monospace">                { Outer.this.x++; }   // allowed???<br></span></div><div style="margin-left:40px"><span style="font-family:monospace">            });<br></span></div><div style="margin-left:40px"><div><span style="font-family:monospace">        }</span></div></div><div style="margin-left:40px"><span style="font-family:monospace">    }</span></div><div style="margin-left:40px"><span style="font-family:monospace">}</span><br></div><br><div>I want to make sure I'm not misunderstanding your proposal.  When you say "treat all class declarations in pre-construction 
context as having no enclosing instance" I still read the phrase 
"enclosing instance" as potentially ambiguous (does that include "2nd 
enclosing instance"? Etc.).</div><div><br></div><div>But previously you said: "Wouldn't it be easier to say that every class declared in a
      pre-construction context is static, period, and cannot reference
      anything from enclosing contexts?" so I'll assume that's what you mean.<br></div><br><div>So the two proposals we're talking about for when an outer class instance expression "Foo.this" is invalid are:<br></div><ol><li>"Foo.this" is invalid when the expression is contained in a Foo early construction context (with any level of nesting) (this is what the JEP proposes)</li><li>"Foo.this" is invalid when the expression is contained in <i>any</i> early construction context (your proposal?)<br></li><li>Is there some other hybrid proposal?<br></li></ol></div><div>I'm not going to argue that #1 is the best in all possible worlds, but I think #1 is better than #2, if only because #2 will cause real-world code out there to start failing to compile - including javac itself.<br></div><div><br></div><div>-Archie<br></div><div><br><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature">Archie L. Cobbs<br></div></div></div>