8256149: Weird AST structure for incomplete member select
Reviewed-by: vromero
This commit is contained in:
parent
a70802477e
commit
d0c526513d
@ -1327,6 +1327,14 @@ public class JavacParser implements Parser {
|
||||
}
|
||||
// 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 @@ public class JavacParser implements Parser {
|
||||
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 @@ public class JavacParserTest extends TestCase {
|
||||
""");
|
||||
}
|
||||
|
||||
@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 = """
|
||||
|
Loading…
Reference in New Issue
Block a user