Skip to content
Permalink
Browse files
8256149: Weird AST structure for incomplete member select
Reviewed-by: vromero
  • Loading branch information
Jan Lahoda committed Dec 8, 2020
1 parent a708024 commit d0c526513d7d82c2a4bb9ef72656cc35de8452e9
Showing 2 changed files with 61 additions and 1 deletion.
@@ -1327,6 +1327,14 @@ protected JCExpression term3() {
}
// typeArgs saved for next loop iteration.
t = toP(F.at(pos).Select(t, ident()));
if (token.pos <= endPosTable.errorEndPos &&
token.kind == MONKEYS_AT) {
//error recovery, case like:
//int i = expr.<missing-ident>
//@Deprecated
if (typeArgs != null) illegal();
return toP(t);
}
if (tyannos != null && tyannos.nonEmpty()) {
t = toP(F.at(tyannos.head.pos).AnnotatedType(tyannos, t));
}
@@ -1534,6 +1542,13 @@ JCExpression term3Rest(JCExpression t, List<JCExpression> typeArgs) {
tyannos = typeAnnotationsOpt();
}
t = toP(F.at(pos1).Select(t, ident(true)));
if (token.pos <= endPosTable.errorEndPos &&
token.kind == MONKEYS_AT) {
//error recovery, case like:
//int i = expr.<missing-ident>
//@Deprecated
break;
}
if (tyannos != null && tyannos.nonEmpty()) {
t = toP(F.at(tyannos.head.pos).AnnotatedType(tyannos, t));
}
@@ -23,7 +23,7 @@

/*
* @test
* @bug 7073631 7159445 7156633 8028235 8065753 8205418 8205913 8228451 8237041 8253584 8246774 8256411
* @bug 7073631 7159445 7156633 8028235 8065753 8205418 8205913 8228451 8237041 8253584 8246774 8256411 8256149
* @summary tests error and diagnostics positions
* @author Jan Lahoda
* @modules jdk.compiler/com.sun.tools.javac.api
@@ -1612,6 +1612,51 @@ String s() {
""");
}

@Test
void testAtRecovery() throws IOException {
//verify the errors and AST form produced for member selects which are
//missing the selected member name and are followed by an annotation:
String code = """
package t;
class Test {
int i1 = "".
@Deprecated
void t1() {
}
int i2 = String.
@Deprecated
void t2() {
}
}
""";
StringWriter out = new StringWriter();
JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(out, fm, null, List.of("-XDrawDiagnostics"),
null, Arrays.asList(new MyFileObject(code)));
String ast = ct.parse().iterator().next().toString().replaceAll("\\R", "\n");
String expected = """
package t;
\n\
class Test {
int i1 = "".<error>;
\n\
@Deprecated
void t1() {
}
int i2 = String.<error>;
\n\
@Deprecated
void t2() {
}
} """;
assertEquals("Unexpected AST, got:\n" + ast, expected, ast);
assertEquals("Unexpected errors, got:\n" + out.toString(),
out.toString().replaceAll("\\R", "\n"),
"""
Test.java:3:17: compiler.err.expected: token.identifier
Test.java:7:21: compiler.err.expected: token.identifier
""");
}

@Test //JDK-8256411
void testBasedAnonymous() throws IOException {
String code = """

1 comment on commit d0c5265

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on d0c5265 Dec 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.