Draft Spec for Second Preview of Flexible Constructor Bodies (JEP 482)

Gavin Bierman gavin.bierman at oracle.com
Tue Jul 16 09:32:16 UTC 2024



On 14 Jul 2024, at 21:14, Archie Cobbs <archie.cobbs at gmail.com> wrote:

I think you are correct in that the spec needs further clarification on those two points.

I can at least confirm that what the compiler currently implements is in fact the intended behavior:

  *   Access to superclass instance fields by any means in an early construction context is not allowed
  *   The rules for "foo", "this.foo", and "C.this.foo" (for the same "foo") in an early construction context should be the same

-Archie

Thanks Stephan. We had already spotted the inconsistency between this.foo and C.this.foo and filed a spec bug: https://bugs.openjdk.org/browse/JDK-8334163

I believe that there are other areas in the spec where they are not treated the same, so I had planned to do a more complete sweep through the spec to consider a more complete fix.

Cheers,
Gavin



On Sun, Jul 14, 2024 at 2:50 PM Stephan Herrmann <stephan.herrmann at berlin.de<mailto:stephan.herrmann at berlin.de>> wrote:
This part doesn't look fully resolved to me:

Am 28.05.24 um 19:20 schrieb Stephan Herrmann:
> [...] > In §8.8.7.1 it says:
>      "References to instance variables of class C are disallowed ..."
> which seems to disqualify the following code:
>
> public class C {
>      String name;
>      C(C other) {
>          System.out.println(other.name<http://other.name/>);
>          super();
>      }
> }
>
> I assume this paragraph in italics is not normative, right? Later paragraphs are
> clear that this applies to single name references and this references, but still
> the above sentence seems misleading. The same applies for the next two sentences
> (regarding other.foo(), or new other.Inner()).
> [...]


While the detailed rules in 15.12.3 look good, the explanation in 8.8.7.1 still
lacks precision. If that explanation is not meant to be precise, maybe it should
indicate this :)

The same problem also exists in the summary in 6.5.7.1 (which is not italics -
explanatory):

"The rules (15.12.3) also prohibit a reference to an instance method occurring
in any one of the following:
...
3. an early construction context (8.8.7.1) of a class where the instance method
is a member."


Interestingly, 6.5.7.1 is more precise regarding qualified this expressions than
what §15.8.4 says about it (see my previous post).

thanks,
Stephan



--
Archie L. Cobbs

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-spec-experts/attachments/20240716/dc3ead84/attachment-0001.htm>


More information about the amber-spec-experts mailing list