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

Vicente Romero vromero at openjdk.org
Fri Mar 22 18:36:54 UTC 2024


On Fri, 1 Mar 2024 17:51:11 GMT, Archie Cobbs <acobbs 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.

this looks good, will do another iteration, but I like it

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

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

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

PR Review: https://git.openjdk.org/jdk/pull/18088#pullrequestreview-1955466746
PR Review Comment: https://git.openjdk.org/jdk/pull/18088#discussion_r1535713758
PR Review Comment: https://git.openjdk.org/jdk/pull/18088#discussion_r1535999652


More information about the compiler-dev mailing list