8253584: Redunant errors for partial member selects
Reviewed-by: vromero
This commit is contained in:
parent
ebf443a16f
commit
86491a5f6b
@ -567,7 +567,7 @@ public class JavacParser implements Parser {
|
|||||||
return ident(false);
|
return ident(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Name ident(boolean advanceOnErrors) {
|
protected Name ident(boolean allowClass) {
|
||||||
if (token.kind == IDENTIFIER) {
|
if (token.kind == IDENTIFIER) {
|
||||||
Name name = token.name();
|
Name name = token.name();
|
||||||
nextToken();
|
nextToken();
|
||||||
@ -603,8 +603,9 @@ public class JavacParser implements Parser {
|
|||||||
return name;
|
return name;
|
||||||
} else {
|
} else {
|
||||||
accept(IDENTIFIER);
|
accept(IDENTIFIER);
|
||||||
if (advanceOnErrors) {
|
if (allowClass && token.kind == CLASS) {
|
||||||
nextToken();
|
nextToken();
|
||||||
|
return names._class;
|
||||||
}
|
}
|
||||||
return names.error;
|
return names.error;
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 7073631 7159445 7156633 8028235 8065753 8205418 8205913 8228451 8237041
|
* @bug 7073631 7159445 7156633 8028235 8065753 8205418 8205913 8228451 8237041 8253584
|
||||||
* @summary tests error and diagnostics positions
|
* @summary tests error and diagnostics positions
|
||||||
* @author Jan Lahoda
|
* @author Jan Lahoda
|
||||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||||
@ -1564,6 +1564,53 @@ public class JavacParserTest extends TestCase {
|
|||||||
assertEquals("Unexpected AST, got:\n" + ast, expected, ast);
|
assertEquals("Unexpected AST, got:\n" + ast, expected, ast);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test //JDK-8253584
|
||||||
|
void testElseRecovery() throws IOException {
|
||||||
|
//verify the errors and AST form produced for member selects which are
|
||||||
|
//missing the selected member name:
|
||||||
|
String code = """
|
||||||
|
package t;
|
||||||
|
class Test {
|
||||||
|
void t() {
|
||||||
|
if (true) {
|
||||||
|
s().
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String s() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
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 {
|
||||||
|
\n\
|
||||||
|
void t() {
|
||||||
|
if (true) {
|
||||||
|
(ERROR);
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
\n\
|
||||||
|
String s() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} """;
|
||||||
|
assertEquals("Unexpected AST, got:\n" + ast, expected, ast);
|
||||||
|
assertEquals("Unexpected errors, got:\n" + out.toString(),
|
||||||
|
out.toString(),
|
||||||
|
"""
|
||||||
|
Test.java:5:17: compiler.err.expected: token.identifier
|
||||||
|
Test.java:5:16: compiler.err.not.stmt
|
||||||
|
""");
|
||||||
|
}
|
||||||
|
|
||||||
void run(String[] args) throws Exception {
|
void run(String[] args) throws Exception {
|
||||||
int passed = 0, failed = 0;
|
int passed = 0, failed = 0;
|
||||||
final Pattern p = (args != null && args.length > 0)
|
final Pattern p = (args != null && args.length > 0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user