<div dir="ltr"><div dir="ltr">On Fri, Jun 14, 2024 at 12:33 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"><u></u>

  
  <div>
    <p>On 14/06/2024 18:04, Archie Cobbs
      wrote:
    </p>
    <blockquote type="cite">Your
      change to the semantics of <span style="font-family:monospace">hasOuterInstance()</span>
      happens to invalidate my <a href="https://urldefense.com/v3/__https://github.com/openjdk/jdk/pull/19705/files*diff-ce037c979a568d769d3064d15f94a75cd0311e3e0a9e7899f59d4f9283ad6ea8__;Iw!!ACWV5N9M2RV99hQ!L-9GAxHAzJt6lxEoIcD-NgGJuM7uictTascht11Ui5uc02DZuGr2sDg5IWBSv_Ei2Gq59ZhAZQhMq9hvL4QIKLPqhvnscg$" target="_blank">fix for JDK-8334248</a>
      but that's OK, the new semantics are more correct and I've
      rewritten my fix to instead check for NOOUTERTHIS directly.</blockquote>
    <p>Thanks. I wonder... is the real problem here that
      Resolve::resolveImplicitThis doesn't skip over classes that have
      NOOUTERTHIS set? E.g. your patch just disables the check if we see
      NOOUTERTHIS... which is ok if the current class happens to have NO
      accessible enclosing instances. But what if there's *some*
      accessible enclosing instance?</p></div></blockquote><div>My current understanding is that my fix is correct because the compiler checks for what it calls an "implicit this" - which we would describe as an "immediate enclosing instance" - separately from non-immediate enclosing instances.</div><div><br></div><div>The reason I say this is that before I made this adjustment (from checking <span style="font-family:monospace">hasOuterInstance()</span> → <span style="font-family:monospace">NOOUTERTHIS == 0</span>) the following program failed to compile:</div></div><div class="gmail_quote"><br></div><div class="gmail_quote" style="margin-left:40px"><span style="font-family:monospace">$ cat EarlyLocalTest3.java</span></div><div class="gmail_quote"><div style="margin-left:40px"><span style="font-family:monospace">public class EarlyLocalTest3 {</span></div><div style="margin-left:40px"><span style="font-family:monospace"><br>    class Test {<br>        Test() {<br>            class InnerLocal { }<br>            Runnable r = InnerLocal::new;<br>            r.run();<br>            super();<br>        }<br>    }<br>}</span></div><div style="margin-left:40px"><span style="font-family:monospace">$ javac -enable-preview --release 24 EarlyLocalTest3.java</span></div><div style="margin-left:40px"><span style="font-family:monospace">../test/langtools/tools/javac/SuperInit/EarlyLocalTest3.java:6: error: cannot reference this before supertype constructor has been called<br>            Runnable r = InnerLocal::new;<br>                         ^</span></div><div><br></div><div>The compiler is detecting that <span style="font-family:monospace">InnerLocal</span> has an outer instance (<span style="font-family:monospace">EarlyLocalTest3</span>) and throwing an error, but that's incorrect because the (<i>non-immediate</i>) outer instance for <span style="font-family:monospace">EarlyLocalTest3</span> is actually accessible at that location.</div><div><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>Btw, it seems like this code crashes javac (even with both
      patches applies). I don't think this code should be allowed at all
      (you can't create the local Foo from the static Bar::r). So, this
      is related to the bug you mentioned, and I believe we need checks
      for the innermost accessible enclosing instance here.</div></blockquote><div><br></div><div>So yes I also see the compiler crashing on that example but I think that may be separate from the issue above...? I don't fully understand this one yet.<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>