RFR: 8194743: Compiler implementation for Statements before super() [v16]
Archie Cobbs
acobbs at openjdk.org
Mon Sep 25 18:17:26 UTC 2023
On Mon, 25 Sep 2023 17:31:57 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:
>> Should this work?
>>
>> class Test {
>> String s = "Hello";
>>
>> void m() {
>> System.out.println("Hello");
>> }
>>
>> class Inner {
>> Inner() {
>> m();
>> super();
>> }
>> }
>>
>> public static void main(String[] args) {
>> new Test().new Inner();
>> }
>> }
>>
>> The proposed changes accept this program. But I can't find supporting text in the JLS changes:
>> https://cr.openjdk.org/~gbierman/jep447/jep447-20230620/specs/statements-before-super-jls.html
>
> After some internal discussion, it is good for javac to accept this, as this case can be supported using the `this$0` parameter that is passed into the constructor of `Inner` (no `this` reference is strictly required). But the JLS text supporting this seems ambiguous:
>
>
> The pre-construction context includes the prologue of the constructor 8.8.7 and the explicit constructor invocation itself. Within a pre-construction context, constructs that refer explicitly or implicitly to the current object are disallowed.
>
>
> It is not clear to me as to whether `m()` refers to the current object or not - as it seems one would have to have intimate knowledge of how the compiler translates the code in order to answer that question.
> where does env1 == env come from?
To be honest I can't remember. At some point it was needed to make something compile, but I can't come up with an example anymore (if you can, I'll tell you why it was there :)
The thinking must have been: "It can't possibly matter if the AST 'cursor' is in the pre-construction context of an outer instance class; it only matters if we are in the pre-construction context of the class under construction."
> The proposed changes accept this program. But I can't find supporting text in the JLS changes
The spec is still being finalized ([here's the latest version](https://cr.openjdk.org/~gbierman/jep447/jep447-20230905/specs/statements-before-super-jls.html#jls-8.8)). The newer §15.12.3 should allow this.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/13656#discussion_r1336237288
More information about the compiler-dev
mailing list