Skip to content

Commit

Permalink
Fix parsing of open module ... {} module declarations
Browse files Browse the repository at this point in the history
Prompted by google/error-prone#4311

PiperOrigin-RevId: 614012108
  • Loading branch information
cushon authored and Javac Team committed Mar 8, 2024
1 parent 0664571 commit 1f0a128
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
6 changes: 5 additions & 1 deletion java/com/google/turbine/parse/Parser.java
Expand Up @@ -210,7 +210,11 @@ public CompUnit compilationUnit() {
&& (ident.value().equals("module") || ident.value().equals("open"))) {
boolean open = false;
if (ident.value().equals("open")) {
ident = eatIdent();
next();
if (token != IDENT) {
throw error(token);
}
ident = ident();
open = true;
}
if (!ident.value().equals("module")) {
Expand Down
Expand Up @@ -47,6 +47,7 @@ public static Iterable<Object[]> parameters() {
"module-info.test", //
"classpath.test",
"multimodule.test",
"module-info-open.test",
};
return ImmutableList.copyOf(testCases).stream().map(x -> new Object[] {x}).collect(toList());
}
Expand All @@ -61,7 +62,7 @@ public ModuleIntegrationTest(String test) {

@Test
public void test() throws Exception {
if (Double.parseDouble(JAVA_CLASS_VERSION.value()) < 53) {
if (Runtime.version().feature() < 9) {
// only run on JDK 9 and later
return;
}
Expand Down
@@ -0,0 +1,5 @@
=== module-info.java ===
open module com.google.foop.annotation {
requires java.base;
requires java.compiler;
}
16 changes: 16 additions & 0 deletions javatests/com/google/turbine/parse/ParseErrorTest.java
Expand Up @@ -475,6 +475,22 @@ public void typeAnnotationBeforeParam() {
" ^"));
}

@Test
public void moduleInfoOpen() {
String input =
lines(
"open {", //
"}");
TurbineError e = assertThrows(TurbineError.class, () -> Parser.parse(input));
assertThat(e)
.hasMessageThat()
.isEqualTo(
lines(
"<>:1: error: unexpected token: {", //
"open {",
" ^"));
}

private static String lines(String... lines) {
return Joiner.on(System.lineSeparator()).join(lines);
}
Expand Down

0 comments on commit 1f0a128

Please sign in to comment.