mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
8256149: Weird AST structure for incomplete member select
Reviewed-by: vromero
This commit is contained in:
parent
a70802477e
commit
d0c526513d
2 changed files with 61 additions and 1 deletions
|
@ -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…
Add table
Add a link
Reference in a new issue