8271928: ErroneousTree with start position -1
Reviewed-by: jlaskey, vromero
This commit is contained in:
parent
adba09b91d
commit
3215dbc8b8
src/jdk.compiler/share/classes/com/sun/tools/javac/tree
test/langtools/tools/javac/parser
@ -548,8 +548,13 @@ public class TreeInfo {
|
|||||||
}
|
}
|
||||||
case ERRONEOUS: {
|
case ERRONEOUS: {
|
||||||
JCErroneous node = (JCErroneous)tree;
|
JCErroneous node = (JCErroneous)tree;
|
||||||
if (node.errs != null && node.errs.nonEmpty())
|
if (node.errs != null && node.errs.nonEmpty()) {
|
||||||
return getStartPos(node.errs.head);
|
int pos = getStartPos(node.errs.head);
|
||||||
|
if (pos != Position.NOPOS) {
|
||||||
|
return pos;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return tree.pos;
|
return tree.pos;
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 7073631 7159445 7156633 8028235 8065753 8205418 8205913 8228451 8237041 8253584 8246774 8256411 8256149 8259050 8266436 8267221
|
* @bug 7073631 7159445 7156633 8028235 8065753 8205418 8205913 8228451 8237041 8253584 8246774 8256411 8256149 8259050 8266436 8267221 8271928
|
||||||
* @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
|
||||||
@ -1795,6 +1795,31 @@ public class JavacParserTest extends TestCase {
|
|||||||
assertEquals("correct parameter type span", code.substring(typeStart, typeEnd), "int[]...");
|
assertEquals("correct parameter type span", code.substring(typeStart, typeEnd), "int[]...");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test //JDK-8271928
|
||||||
|
void testX() throws IOException {
|
||||||
|
String code = """
|
||||||
|
package test;
|
||||||
|
public static void test() {
|
||||||
|
return test;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
|
JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, fm, null,
|
||||||
|
null, null, Arrays.asList(new MyFileObject(code)));
|
||||||
|
CompilationUnitTree cut = ct.parse().iterator().next();
|
||||||
|
SourcePositions sp = Trees.instance(ct).getSourcePositions();
|
||||||
|
new TreePathScanner<Void, Void>() {
|
||||||
|
@Override
|
||||||
|
public Void visitErroneous(ErroneousTree tree, Void p) {
|
||||||
|
int pos = (int) sp.getStartPosition(cut, tree);
|
||||||
|
if (pos == (-1)) {
|
||||||
|
fail("Invalid source position for an ErroneousTree");
|
||||||
|
}
|
||||||
|
return scan(tree.getErrorTrees(), p);
|
||||||
|
}
|
||||||
|
}.scan(cut, null);
|
||||||
|
}
|
||||||
|
|
||||||
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