mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
8267221: jshell feedback is incorrect when creating method with array varargs parameter
Reviewed-by: vromero
This commit is contained in:
parent
bf8d4a8eca
commit
f632254943
3 changed files with 34 additions and 2 deletions
|
@ -23,7 +23,7 @@
|
|||
|
||||
/*
|
||||
* @test
|
||||
* @bug 7073631 7159445 7156633 8028235 8065753 8205418 8205913 8228451 8237041 8253584 8246774 8256411 8256149 8259050 8266436
|
||||
* @bug 7073631 7159445 7156633 8028235 8065753 8205418 8205913 8228451 8237041 8253584 8246774 8256411 8256149 8259050 8266436 8267221
|
||||
* @summary tests error and diagnostics positions
|
||||
* @author Jan Lahoda
|
||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||
|
@ -1775,6 +1775,27 @@ public class JavacParserTest extends TestCase {
|
|||
assertEquals("expected null as constructor return type", constr.getReturnType(), null);
|
||||
}
|
||||
|
||||
@Test //JDK-8267221
|
||||
void testVarArgArrayParameter() throws IOException {
|
||||
String code = """
|
||||
package test;
|
||||
public class Test {
|
||||
private void test(int[]... p) {}
|
||||
}
|
||||
""";
|
||||
|
||||
JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, fm, null,
|
||||
null, null, Arrays.asList(new MyFileObject(code)));
|
||||
CompilationUnitTree cut = ct.parse().iterator().next();
|
||||
ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0);
|
||||
MethodTree constr = (MethodTree) clazz.getMembers().get(0);
|
||||
VariableTree param = constr.getParameters().get(0);
|
||||
SourcePositions sp = Trees.instance(ct).getSourcePositions();
|
||||
int typeStart = (int) sp.getStartPosition(cut, param.getType());
|
||||
int typeEnd = (int) sp.getEndPosition(cut, param.getType());
|
||||
assertEquals("correct parameter type span", code.substring(typeStart, typeEnd), "int[]...");
|
||||
}
|
||||
|
||||
void run(String[] args) throws Exception {
|
||||
int passed = 0, failed = 0;
|
||||
final Pattern p = (args != null && args.length > 0)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue