RFR: 8325805: Compiler Implementation for Flexible Constructor Bodies (Second Preview)

Archie Cobbs acobbs at openjdk.org
Fri Mar 22 18:36:54 UTC 2024


On Fri, 22 Mar 2024 14:48:35 GMT, Vicente Romero <vromero at openjdk.org> wrote:

>> This patch changes the compiler to allow constructors to make assignments to fields prior to the `super()` invocation, i.e., in the pre-construction context.  This is part of the work associated with [JDK-8325803 - Flexible Constructor Bodies (Second Preview)](https://bugs.openjdk.org/browse/JDK-8325803).
>> 
>> This patch is based the relevant bits from @vicente-romero-oracle's commit [1b99b5cf](https://github.com/openjdk/valhalla/commit/1b99b5cfd9a5d484b9e7bdfc284daad9ad6535bf) to the valhalla repo.
>
> src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java line 3850:
> 
>> 3848:         // Check assumptions
>> 3849:         Assert.check(env.info.ctorPrologue);
>> 3850:         Assert.check((v.flags() & STATIC) == 0);
> 
> nit: I would prefer here to directly read the `flags_field` field instead of invoking `Symbol::flags` as the later can provoke symbol completions. Probably not a big deal here but just to be on the safe side

Thanks - I didn't realize there could be side effects, and it's especially appropriate to avoid them because this is just an assertion statement.

Fixed in 34aa494680f.

> test/langtools/tools/javac/DefiniteAssignment/DA_DUConstructors.java line 3:
> 
>> 1: /*
>> 2:  * @test /nodynamiccopyright/
>> 3:  * @bug 8324873
> 
> just paperwork-ish, I'm not sure we should refer to a valhalla bug and keep the valhalla summary below. I get why you are doing it but I guess this current fix will be pushed before valhalla. So I would just use this current bug ID and summary and once we do a merge of this test in the valhalla repo we can add more information to it

No I completely agree - two different repo's. Cut & paste glitch.

Fixed in 4d2d3e83c42.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/18088#discussion_r1535722543
PR Review Comment: https://git.openjdk.org/jdk/pull/18088#discussion_r1536017601


More information about the compiler-dev mailing list