Integrated: 8310314: Misplaced "unnamed classes are a preview feature and are disabled by default" error

Jan Lahoda jlahoda at openjdk.org
Tue Jun 20 07:06:34 UTC 2023


On Mon, 19 Jun 2023 15:51:13 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:

> Consider code like:
> 
> $ cat Test.java
> void main() {
>     System.err.println("Hello!");
> }
> 
> 
> Currently, the "unnamed classes are a preview feature and are disabled by default" error is put at the end of the file:
> 
> $ java Test.java
> Test.java:4: error: unnamed classes are a preview feature and are disabled by default.
> 
>   (use --enable-preview to enable unnamed classes)
> 1 error
> error: compilation failed
> 
> 
> This does not seem to be user friendly. It seems to me that putting the error on the first method/variable in the file would be better:
> 
> $ java Test.java
> Test.java:1: error: unnamed classes are a preview feature and are disabled by default.
> void main() {
> ^
>   (use --enable-preview to enable unnamed classes)
> 1 error
> error: compilation failed
> 
> 
> The proposed patch is to simply move the source level check to the place where the top-level method or field is parsed. Calling the method multiple times for a single file should not be a problem - `Log` itself will prevent printing the error multiple times for the same file.

This pull request has now been integrated.

Changeset: 79069c5e
Author:    Jan Lahoda <jlahoda at openjdk.org>
URL:       https://git.openjdk.org/jdk/commit/79069c5e748a274c45dec72aad082c31eff418d1
Stats:     18 lines in 3 files changed: 16 ins; 2 del; 0 mod

8310314: Misplaced "unnamed classes are a preview feature and are disabled by default" error

Reviewed-by: jlaskey

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

PR: https://git.openjdk.org/jdk/pull/14544


More information about the compiler-dev mailing list