A possible bug in JEP 482: Flexible Constructor Bodies
Remi Forax
forax at univ-mlv.fr
Mon May 20 21:43:04 UTC 2024
> From: "Ella Ananeva" <ella.ananeva at oracle.com>
> To: "amber-dev" <amber-dev at openjdk.org>
> Sent: Monday, May 20, 2024 11:12:55 PM
> Subject: A possible bug in JEP 482: Flexible Constructor Bodies
> Hi,
> I found a discrepancy in the behavior of the JEP 482 compiler regarding definite
> assignment of a final non-static blank field in a prologue of a constructor:
> Case 1
> Case 2
> Case 3
> class Q {
> final int x ;
> int y ;
> { y = x ; }
> public Q ( int a ) {
> x = a ;
> super ();
> }
> }
> class Q {
> final int x ;
> int y ;
> { y = x ; }
> public Q ( int a ) {
> x = a ;
> this ();
> }
> public Q () {}
> }
> class Q {
> final int x ;
> int y ;
> { y = x ; }
> public Q ( int a ) {
> x = a ;
> }
> }
> Compilation succeeds
> Compilation fails
> Compilation fails
> Shouldn’t the behavior in this 3 cases be similar?
Hello,
case 3 is equivalent to
class Q {
final int x ;
int y ;
public Q ( int a ) {
y = x ;
x = a ;
}
}
so 'y' can not be initialized by 'x' given that 'x' is not initialized.
case 1 is equivalent to
class Q {
final int x ;
int y ;
public Q ( int a ) {
x = a ;
super ();
y = x ;
}
}
so it compiles correctly, when y = x is executed, x is already initialized.
For me, case 2 is a compiler bug, the call to this() is indirectly a super constructor call.
> Thank you,
> Ella
regards,
Rémi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20240520/b075411b/attachment-0001.htm>
More information about the amber-dev
mailing list