8014021: TreeMaker.Params behaves inconsistently when the owning method has the same number of parameters as the number of parameter types requested

Reviewed-by: vromero, jlahoda
This commit is contained in:
Archie L. Cobbs 2023-03-17 22:12:09 +00:00 committed by Vicente Romero
parent 8f5bb538ab
commit 254288a518
2 changed files with 21 additions and 14 deletions

View File

@ -1378,7 +1378,7 @@ public class TypeEnter implements Completer {
@Override
public List<Name> superArgs() {
List<JCVariableDecl> params = make.Params(constructorType().getParameterTypes(), constructorSymbol());
List<JCVariableDecl> params = make.Params(constructorSymbol());
if (!enclosingType().hasTag(NONE)) {
params = params.tail;
}

View File

@ -1035,7 +1035,7 @@ public class TreeMaker implements JCTree.Factory {
m.name != names.init ? Type(mtype.getReturnType()) : null,
TypeParams(mtype.getTypeArguments()),
null, // receiver type
Params(mtype.getParameterTypes(), m),
m.params != null ? Params(m) : Params(m, mtype.getParameterTypes()),
Types(mtype.getThrownTypes()),
body,
null,
@ -1064,20 +1064,27 @@ public class TreeMaker implements JCTree.Factory {
return VarDef(new VarSymbol(PARAMETER, name, argtype, owner), null);
}
/** Create a list of value parameter trees x0, ..., xn from a list of
* their types and their owner.
/** Create a list of value parameter trees for a method's parameters
* using the same names as the method's existing parameters.
*/
public List<JCVariableDecl> Params(List<Type> argtypes, Symbol owner) {
public List<JCVariableDecl> Params(MethodSymbol mth) {
Assert.check(mth.params != null);
ListBuffer<JCVariableDecl> params = new ListBuffer<>();
MethodSymbol mth = (owner.kind == MTH) ? ((MethodSymbol)owner) : null;
if (mth != null && mth.params != null && argtypes.length() == mth.params.length()) {
for (VarSymbol param : ((MethodSymbol)owner).params)
params.append(VarDef(param, null));
} else {
int i = 0;
for (List<Type> l = argtypes; l.nonEmpty(); l = l.tail)
params.append(Param(paramName(i++), l.head, owner));
}
for (VarSymbol param : mth.params)
params.append(VarDef(param, null));
return params.toList();
}
/** Synthesize a list of parameter trees for a method's parameters.
* Used for methods with no parameters defined, e.g. bridge methods.
* The placeholder names will be x0, x1, ..., xn.
*/
public List<JCVariableDecl> Params(MethodSymbol mth, List<Type> argtypes) {
Assert.check(mth.params == null);
ListBuffer<JCVariableDecl> params = new ListBuffer<>();
int i = 0;
for (List<Type> l = argtypes; l.nonEmpty(); l = l.tail)
params.append(Param(paramName(i++), l.head, mth));
return params.toList();
}