RFR: 8310314: Misplaced "unnamed classes are a preview feature and are disabled by default" error
Jim Laskey
jlaskey at openjdk.org
Mon Jun 19 16:12:47 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.
LGTM
-------------
Marked as reviewed by jlaskey (Reviewer).
PR Review: https://git.openjdk.org/jdk/pull/14544#pullrequestreview-1486532652
More information about the compiler-dev
mailing list