Loosening requirements for super() invocation
Archie Cobbs
archie.cobbs at gmail.com
Tue Jan 24 21:24:12 UTC 2023
On Tue, Jan 24, 2023 at 2:21 PM Brian Goetz <brian.goetz at oracle.com> wrote:
>
> This made me realize there is another missing requirement:
>
> - Upon normal return from a constructor, the `this` reference must be
> DA
>
>
> So, I think this is true by definition; on normal return from a
> super/this/implicit super call, then `this` *is* DA.
>
> You can simplify the rule about try blocks to:
>
> - if `this` is DU on entry to a try block, it must be DU on normal
> completion of the try block.
>
> Can you simplify further, while still preventing `this` calls inside a try
> block? I don't think so, since we might want to allow a try block before
> the super/this call.
>
Ok thanks. I admit I'm getting a little out of my league here.
Does this sound correct?
The JLS will be modified as follows:
* Remove the requirement that `super()` or `this()` appear as the first
statement in a constructor
* Add superclass initialization to the existing constructor dataflow
analysis as follows:
* The `this` reference is considered DU on entry to the constructor
* Before a `this()` or `super()` call, the `this` reference must be DU
* After a `this()` or `super()` call, the `this` reference is
considered DA
* Before normal completion of the constructor, the `this` reference
must be DA
* If `this` is DU on entry to a `try` block, it must be DU on normal
completion of the `try` block
* If no explicit `this()` or `super()` appears in a constructor, it is
treated as if the first line of the constructor were `super()`
* Add the following restrictions on constructors:
* No access to `this`, other than assignments to fields, may occur
unless `this` is DA
* `super()` and `this()` may not appear within any `try { }` block
* Clarify that non-static field initializers and initialization blocks are
executed immediately after `super()` invocation, wherever it occurs (see
"Initialization Order" below)
Thanks,
-Archie
--
Archie L. Cobbs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20230124/b9f096fb/attachment.htm>
More information about the amber-dev
mailing list