Skip to content
This repository was archived by the owner on Sep 19, 2023. It is now read-only.
/ jdk21 Public archive

Commit ede16cd

Browse files
committed
8310314: Misplaced "unnamed classes are a preview feature and are disabled by default" error
Reviewed-by: jlaskey Backport-of: 79069c5e748a274c45dec72aad082c31eff418d1
1 parent 08965e6 commit ede16cd

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -3995,6 +3995,7 @@ public JCTree.JCCompilationUnit parseCompilationUnit() {
39953995
}
39963996

39973997
if (isTopLevelMethodOrField) {
3998+
checkSourceLevel(token.pos, Feature.UNNAMED_CLASSES);
39983999
defs.appendList(topLevelMethodOrFieldDeclaration(mods));
39994000
isUnnamedClass = true;
40004001
} else {
@@ -4025,8 +4026,6 @@ public JCTree.JCCompilationUnit parseCompilationUnit() {
40254026

40264027
// Restructure top level to be an unnamed class.
40274028
private List<JCTree> constructUnnamedClass(List<JCTree> origDefs) {
4028-
checkSourceLevel(Feature.UNNAMED_CLASSES);
4029-
40304029
ListBuffer<JCTree> topDefs = new ListBuffer<>();
40314030
ListBuffer<JCTree> defs = new ListBuffer<>();
40324031

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* @test /nodynamiccopyright/
3+
* @bug 8310314
4+
* @summary Ensure proper error position for the "unnamed classes not supported" error
5+
* @compile/fail/ref=SourceLevelErrorPosition.out -XDrawDiagnostics SourceLevelErrorPosition.java
6+
*/
7+
class Nested {}
8+
void main() {
9+
System.err.println("");
10+
}
11+
void test() {
12+
System.err.println("");
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
SourceLevelErrorPosition.java:8:1: compiler.err.preview.feature.disabled.plural: (compiler.misc.feature.unnamed.classes)
2+
1 error

0 commit comments

Comments
 (0)