<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    <font size="4"><font face="monospace">My sense is that the spec got
        a little over-zealous calling the preamable of a constructor a
        "static context".  This was accurate prior to generics, but no
        longer accurate when class type variables are involved because
        constructors are instance "members".  <br>
        <br>
        The logical fix IMO is to sever the link to "static context" in
        8.8.7.  Currently it says:<br>
        <br>
        <blockquote type="cite"><font size="4"><font face="monospace">An
              explicit constructor invocation statement introduces a
              static context (§8.1.3),<br>
              which limits the use of constructs that refer to the
              current object. Notably, the<br>
              keywords this and super are prohibited in a static context
              (§15.8.3, §15.11.2),<br>
              as are unqualified references to instance variables,
              instance methods, and type<br>
              parameters of lexically enclosing declarations (§6.5.5.1,
              §6.5.6.1, §15.12.3).<br>
            </font></font></blockquote>
        <br>
        This can be amended to:<br>
        <br>
        An explicit constructor invocation statement introduces an
        _pre-initialization context_, which limits the use of constructs
        that refer to the current object.  Notably, the keywords `this`
        and `super` are prohibited in a pre-initialization context, as
        are unqualified references to instance variables and instance
        methods of lexically enclosing declarations.  <br>
        <br>
        Then static context still means what it means, we are just being
        honest that the preamble of a constructor body is something
        different, and we spell out the restrictions of what that means
        directly in 8.8.7.  <br>
        <br>
        <br>
        <br>
      </font></font><br>
    <div class="moz-cite-prefix">On 2/2/2023 3:09 PM, Archie Cobbs
      wrote:<br>
    </div>
    <blockquote type="cite" cite="mid:CANSoFxv0v5Cxq822bx42NjKr4CTWj1kf262xbOz690H87B87EQ@mail.gmail.com">
      
      <div dir="ltr">
        <div dir="ltr">On Tue, Jan 31, 2023 at 2:45 PM Archie Cobbs <<a href="mailto:archie.cobbs@gmail.com" target="_blank" moz-do-not-send="true" class="moz-txt-link-freetext">archie.cobbs@gmail.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">
            <div dir="ltr">Obviously this change requires a JEP, and so
              we have this JEP draft for review:
              <div><br>
              </div>
              <div style="margin-left:40px"><a href="https://bugs.openjdk.org/browse/JDK-8300786" target="_blank" moz-do-not-send="true">JDK-8300786</a>
                - No longer require super() and this() to appear first
                in a constructor</div>
            </div>
          </blockquote>
          <div><br>
          </div>
          Update on this JEP.</div>
        <div class="gmail_quote"><br>
        </div>
        <div class="gmail_quote">Doing a little more research I
          discovered that since Java 8 the compiler has not been
          following the spec as it applies to allowing type parameters
          inside <span style="font-family:monospace">super()</span>
          calls (bug filed as <a href="https://bugs.openjdk.org/browse/JDK-8301649" moz-do-not-send="true">JDK-8301649</a>).</div>
        <div class="gmail_quote">
          <div class="gmail_quote"><br>
          </div>
          <div class="gmail_quote">The spec says this is a "static
            context", so type parameters are in theory not allowed. But
            the compiler allows it, and in fact it seems the spec is
            being too restrictive.<br>
          </div>
          <div class="gmail_quote"><br>
            <div class="gmail_quote">With the change in this JEP, this
              discrepancy will only get worse, because the "static
              context" that's part of a constructor can now include a
              lot more stuff.<br>
            </div>
            <div class="gmail_quote"><br>
            </div>
          </div>
        </div>
        <div class="gmail_quote">In <a href="https://mail.openjdk.org/pipermail/compiler-dev/2023-February/021960.html" target="_blank" moz-do-not-send="true">this discussion on
            compiler-dev</a> it was generally agreed that the spec
          should probably be fixed as part of this JEP.</div>
        <div class="gmail_quote"><br>
        </div>
        <div class="gmail_quote">So I'm wondering about people's
          thoughts on this list - not only whether to fix the spec, but
          also how exactly to do so, any other suggestions, etc.<br>
        </div>
        <div class="gmail_quote"><br>
        </div>
        <div class="gmail_quote">I see two options:</div>
        <ol>
          <li>Split "static context" in two:<br>
          </li>
          <ol>
            <li>The old "static context" gets renamed to "lexically
              static context". References to anything non-static are
              disallowed - same as now.<br>
            </li>
            <li>Define a new "referentially static context" which
              disallows any references to 'this' (explicit or implicit)
              but allows type parameters, etc.</li>
          </ol>
          <li>Leave "static context" alone, but add an exception to how
            it applies prior to <span style="font-family:monospace">super()</span>
            so that it permits type parameters, etc.</li>
        </ol>
        <div>
          <div class="gmail_quote">Or maybe there is another option... ?</div>
          <div class="gmail_quote"><br>
          </div>
          <div class="gmail_quote">Thoughts?<br>
          </div>
          <div class="gmail_quote"><br>
          </div>
          <div class="gmail_quote">Thanks,<br>
          </div>
          <div class="gmail_quote">-Archie<br>
          </div>
          <br>
          -- <br>
          <div dir="ltr">Archie L. Cobbs<br>
          </div>
        </div>
      </div>
    </blockquote>
    <br>
  </body>
</html>