Skip to content

Commit

Permalink
Handling semicolons.
Browse files Browse the repository at this point in the history
  • Loading branch information
lahodaj committed Aug 14, 2024
1 parent 475df82 commit d286a1a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4088,6 +4088,15 @@ public JCTree.JCCompilationUnit parseCompilationUnit() {

mods = null;
firstTypeDecl = false;

//TODO: better?
while (mods == null && token.kind == SEMI) {
nextToken();
semiList.append(toP(F.at(pos).Skip()));
if (token.kind == EOF)
break OUTER;
}
//better? end
}
}
List<JCTree> topLevelDefs = isImplicitClass ? constructImplicitClass(defs.toList()) : defs.toList();
Expand Down
22 changes: 22 additions & 0 deletions test/langtools/tools/javac/ImplicitClass/ErrorRecovery.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,26 @@ public void testBrokenVariable(Path base) throws Exception {
", while expecting: " + expected);
}
}

@Test
public void testExtraSemi(Path base) throws Exception {
Path current = base.resolve(".");
Path src = current.resolve("src");
Path classes = current.resolve("classes");
tb.writeFile(src.resolve("Test.java"),
"""
class C {};
void main() {};
""");

Files.createDirectories(classes);

new JavacTask(tb)
.options("-XDrawDiagnostics",
"--enable-preview", "--release", SOURCE_VERSION)
.outdir(classes)
.files(tb.findJavaFiles(src))
.run(Task.Expect.SUCCESS)
.writeAll();
}
}

0 comments on commit d286a1a

Please sign in to comment.