|
23 | 23 |
|
24 | 24 | /*
|
25 | 25 | * @test
|
26 |
| - * @bug 7073631 7159445 7156633 8028235 8065753 8205418 8205913 8228451 8237041 |
| 26 | + * @bug 7073631 7159445 7156633 8028235 8065753 8205418 8205913 8228451 8237041 8253584 |
27 | 27 | * @summary tests error and diagnostics positions
|
28 | 28 | * @author Jan Lahoda
|
29 | 29 | * @modules jdk.compiler/com.sun.tools.javac.api
|
@@ -1564,6 +1564,53 @@ public class B {
|
1564 | 1564 | assertEquals("Unexpected AST, got:\n" + ast, expected, ast);
|
1565 | 1565 | }
|
1566 | 1566 |
|
| 1567 | + @Test //JDK-8253584 |
| 1568 | + void testElseRecovery() throws IOException { |
| 1569 | + //verify the errors and AST form produced for member selects which are |
| 1570 | + //missing the selected member name: |
| 1571 | + String code = """ |
| 1572 | + package t; |
| 1573 | + class Test { |
| 1574 | + void t() { |
| 1575 | + if (true) { |
| 1576 | + s(). |
| 1577 | + } else { |
| 1578 | + } |
| 1579 | + } |
| 1580 | + String s() { |
| 1581 | + return null; |
| 1582 | + } |
| 1583 | + } |
| 1584 | + """; |
| 1585 | + StringWriter out = new StringWriter(); |
| 1586 | + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(out, fm, null, List.of("-XDrawDiagnostics"), |
| 1587 | + null, Arrays.asList(new MyFileObject(code))); |
| 1588 | + String ast = ct.parse().iterator().next().toString().replaceAll("\\R", "\n"); |
| 1589 | + String expected = """ |
| 1590 | + package t; |
| 1591 | + \n\ |
| 1592 | + class Test { |
| 1593 | + \n\ |
| 1594 | + void t() { |
| 1595 | + if (true) { |
| 1596 | + (ERROR); |
| 1597 | + } else { |
| 1598 | + } |
| 1599 | + } |
| 1600 | + \n\ |
| 1601 | + String s() { |
| 1602 | + return null; |
| 1603 | + } |
| 1604 | + } """; |
| 1605 | + assertEquals("Unexpected AST, got:\n" + ast, expected, ast); |
| 1606 | + assertEquals("Unexpected errors, got:\n" + out.toString(), |
| 1607 | + out.toString(), |
| 1608 | + """ |
| 1609 | + Test.java:5:17: compiler.err.expected: token.identifier |
| 1610 | + Test.java:5:16: compiler.err.not.stmt |
| 1611 | + """); |
| 1612 | + } |
| 1613 | + |
1567 | 1614 | void run(String[] args) throws Exception {
|
1568 | 1615 | int passed = 0, failed = 0;
|
1569 | 1616 | final Pattern p = (args != null && args.length > 0)
|
|
0 commit comments