Compiler error message not clear for Valhalla EA 2
Remi Forax
forax at univ-mlv.fr
Wed Oct 29 08:49:35 UTC 2025
> From: "Remi Forax" <forax at univ-mlv.fr>
> To: "David Alayachew" <davidalayachew at gmail.com>
> Cc: "valhalla-dev" <valhalla-dev at openjdk.org>
> Sent: Wednesday, October 29, 2025 9:30:22 AM
> Subject: Re: Compiler error message not clear for Valhalla EA 2
> This is an interesting case because i'm not sure the compiler should emit an
> error here.
> Currently the error occurs because as you said the call to super() is added
> after the call to throw.
> But throwing an exception in a constructor of an identity class is valid, and i
> do not see a reason why this behavior should not be the same in the case of a
> value class.
or perhaps javac should behave more like when there is an explicit call to 'return'
value class V {
V ( int v ) {
return ;
}
}
java: 'return' not allowed before explicit constructor invocation
> regards,
> Rémi
regards,
Rémi
>> From: "David Alayachew" <davidalayachew at gmail.com>
>> To: "valhalla-dev" <valhalla-dev at openjdk.org>
>> Sent: Wednesday, October 29, 2025 5:30:23 AM
>> Subject: Re: Compiler error message not clear for Valhalla EA 2
>> The compiler error message goes away if I put a super(); as the first statement
>> in the constructor. But still, that error message could be clearer.
>> From: "David Alayachew" <davidalayachew at gmail.com>
>> To: "valhalla-dev" <valhalla-dev at openjdk.org>
>> Sent: Wednesday, October 29, 2025 5:27:55 AM
>> Subject: Compiler error message not clear for Valhalla EA 2
>> Hello [ mailto:valhalla-dev at openjdk.org | @valhalla-dev ] ,
>> While testing out the new Valhalla EA that came out a few days ago, I ran into
>> the following compiler error.
>> Here is a minified example.
>> public value class abc
>> {
>> public abc()
>> {
>> throw new UnsupportedOperationException();
>> }
>> public static void someHelperMethod()
>> {}
>> }
>> And here is the compiler error message.
>> $ java --enable-preview abc.java
>> abc.java:5: error: unreachable statement
>> {
>> ^
>> 1 error
>> error: compilation failed
>> That location is the opening curly brace of the constructor.
>> Can we have a more clear error message?
>> Thank you for your time and consideration.
>> David Alayachew
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/valhalla-dev/attachments/20251029/5f300c13/attachment-0001.htm>
More information about the valhalla-dev
mailing list