[lworld] RFR: 8358777: [lworld] Allow explicit super invocation in canonical constructors

Chen Liang liach at openjdk.org
Tue Jun 10 19:28:48 UTC 2025


On Tue, 10 Jun 2025 17:02:31 GMT, Vicente Romero <vromero at openjdk.org> wrote:

> This is the implementation of section `Record class constructors` of JEP 401, see [1]. This PR allows a normal canonical constructor for a record class to contain an explicit 'super()' call, expressing an explicit division between early and late construction. Same applies to identity record classes
> 
> [1] https://bugs.openjdk.org/browse/JDK-8317277
> 
> Note: this PR depends on flexible constructor bodies, given that the change that makes it a final feature is not merged in lworld yet I will wait for that to happen to do a merge and then push this fix

This is mixed with a few flexible constructor bodies finalization changes. We should update lworld with these changes from master to make this patch cleaner.

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java line 1129:

> 1127:                             }
> 1128: 
> 1129:                             if (!allowValueClasses && TreeInfo.hasAnyConstructorCall(tree)) {

When we allow value classes/early construction, we still wish to block this-delegating constructor calls. This works as a temporary measure.

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java line 1243:

> 1241:                 if (isInstanceFieldOfValueClass || isRecordField) {
> 1242:                     implicit |= FINAL | STRICT;
> 1243:                 }

Suggestion:

                if (isInstanceFieldOfValueClass || isRecordField) {
                    implicit |= FINAL | STRICT;
                    mask = ValueFieldFlags;
                } else {
                    mask = VarFlags;
                }

test/langtools/tools/javac/records/RecordReading.java line 102:

> 100:                 \n\
> 101:                 public record R(int i, @A long j, java.util.List<java.lang.String> l) {
> 102:                   private final strictfp int i;

Should we update `PrintingProcessor::printModifiers` instead? Either rename this modifier or to mask remove strict bit for fields?

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

PR Review: https://git.openjdk.org/valhalla/pull/1483#pullrequestreview-2914790373
PR Review Comment: https://git.openjdk.org/valhalla/pull/1483#discussion_r2138616176
PR Review Comment: https://git.openjdk.org/valhalla/pull/1483#discussion_r2138619225
PR Review Comment: https://git.openjdk.org/valhalla/pull/1483#discussion_r2138609263


More information about the valhalla-dev mailing list