On Sat, 15 Nov 2025 14:24:42 GMT, Vicente Romero <[email protected]> wrote:

>> Javac is accepting this code:
>> 
>> 
>> abstract value class ValueParent {
>>     int b = 5;
>> }
>> 
>> value class ValueClass extends ValueParent {
>>     int a = b;
>> }
>> 
>> This is not allowed as in value classes field initializers will run in the 
>> prologue phase where references to super class fields are forbidden
>> 
>> TIA
>
> Vicente Romero has updated the pull request with a new target base due to a 
> merge or a rebase. The incremental webrev excludes the unrelated changes 
> brought in by the merge/rebase. The pull request contains six additional 
> commits since the last revision:
> 
>  - adding test
>  - Merge branch 'lworld' into JDK-8371382
>  - fixing bug
>  - Merge branch 'lworld' into JDK-8371382
>  - additional test
>  - 8371382: [lworld] Javac accepts field initializer that refers to a 
> superclass field

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

> 1521:                             (!localEnv.enclClass.sym.isValueClass() &&
> 1522:                              (sym.flags_field & HASINIT) != 0 &&
> 1523:                              !isInitializer))

it is OK for a field with initializer to refer to another field with 
initializer, so no warning or error if we are analyzing a field initializer

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

PR Review Comment: 
https://git.openjdk.org/valhalla/pull/1728#discussion_r2529920759

Reply via email to