8267221: jshell feedback is incorrect when creating method with array varargs parameter
Reviewed-by: vromero
This commit is contained in:
parent
bf8d4a8eca
commit
f632254943
@ -4555,6 +4555,7 @@ public class JavacParser implements Parser {
|
||||
|
||||
if (createNewLevel) {
|
||||
mostInnerType = to(F.at(token.pos).TypeArray(mostInnerType));
|
||||
origEndPos = getEndPos(mostInnerType);
|
||||
}
|
||||
|
||||
JCExpression mostInnerTypeToReturn = mostInnerType;
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8080357 8167643 8187359 8199762 8080353 8246353 8247456
|
||||
* @bug 8080357 8167643 8187359 8199762 8080353 8246353 8247456 8267221
|
||||
* @summary Tests for EvaluationState.methods
|
||||
* @build KullaTesting TestingInputStream ExpectedDiagnostic
|
||||
* @run testng MethodsTest
|
||||
@ -374,4 +374,14 @@ public class MethodsTest extends KullaTesting {
|
||||
assertNumberOfActiveMethods(0);
|
||||
assertActiveKeys();
|
||||
}
|
||||
|
||||
//JDK-8267221:
|
||||
public void testMethodArrayParameters() {
|
||||
MethodSnippet m1 = methodKey(assertEval("void m1(int... p) { }", added(VALID)));
|
||||
assertEquals(m1.parameterTypes(), "int...");
|
||||
MethodSnippet m2 = methodKey(assertEval("void m2(int[]... p) { }", added(VALID)));
|
||||
assertEquals(m2.parameterTypes(), "int[]...");
|
||||
MethodSnippet m3 = methodKey(assertEval("void m3(int[][] p) { }", added(VALID)));
|
||||
assertEquals(m3.parameterTypes(), "int[][]");
|
||||
}
|
||||
}
|
||||
|
@ -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…
x
Reference in New Issue
Block a user