RFR: 8310314: Misplaced "unnamed classes are a preview feature and are disabled by default" error
Jan Lahoda
jlahoda at openjdk.org
Mon Jun 19 15:59:27 UTC 2023
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.
-------------
Commit messages:
- Improving test metadata
- Enhancing test.
- 8310314: Misplaces "unnamed classes are a preview feature and are disabled by default" error
Changes: https://git.openjdk.org/jdk/pull/14544/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=14544&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8310314
Stats: 18 lines in 3 files changed: 16 ins; 2 del; 0 mod
Patch: https://git.openjdk.org/jdk/pull/14544.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/14544/head:pull/14544
PR: https://git.openjdk.org/jdk/pull/14544
More information about the compiler-dev
mailing list