Skip to content

Commit 2338a2a

Browse files
committed
transpiler fix for varargs with mix of raw and generic parameter types.
// BH: can't just check for an array; it has to be an array with // the right component type // NOTE: This is still not quite right. // It will not pass a true primitive numeric array type -- // int[]... value will be [1,2,3], not Int32Array(1,2,3)
1 parent c41d2c0 commit 2338a2a

File tree

1 file changed

+33
-9
lines changed

1 file changed

+33
-9
lines changed

sources/net.sf.j2s.core/src/net/sf/j2s/core/Java2ScriptVisitor.java

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2756,9 +2756,9 @@ private void addSuperConstructor(SuperConstructorInvocation node, IMethodBinding
27562756
}
27572757
buffer.append(getFinalMethodNameWith$Params(";C$.superclazz.c$", null, node.resolveConstructorBinding(), null,
27582758
false, null, METHOD_NOTSPECIAL));
2759-
buffer.append(".apply(this");
2760-
addMethodParameterList(node.arguments(), methodDeclaration, ", [", "]", METHOD_CONSTRUCTOR);
2761-
buffer.append(")");
2759+
buffer.append(".apply(this,[");
2760+
addMethodParameterList(node.arguments(), methodDeclaration, null, null, METHOD_CONSTRUCTOR);
2761+
buffer.append("])");
27622762
addCallInit();
27632763
}
27642764

@@ -4225,11 +4225,35 @@ private void addMethodArguments(ITypeBinding[] parameterTypes, boolean methodIsV
42254225
String op = (isIndexOf && i == 0 ? "q" : "p");
42264226
if (i == nparam - 1) {
42274227
// BH: can't just check for an array; it has to be an array with
4228-
// the right number of dimensions
4229-
if (nparam != argCount || methodIsVarArgs && paramType.isArray()
4230-
&& arg.resolveTypeBinding().getDimensions() != paramType.getDimensions()
4231-
&& !(arg instanceof NullLiteral)) {
4228+
// the right component type
4229+
// NOTE: This is still not quite right.
4230+
// It will not pass a true primitive numeric array type --
4231+
// int[]... value will be [1,2,3], not Int32Array(1,2,3)
4232+
// Also, for a generic, we could have a problem if there is only one
4233+
// argument, and it is an array.
4234+
4235+
ITypeBinding atype = null;
4236+
if (nparam != argCount // clearly need [ ]
4237+
||methodIsVarArgs // only one argument - might need [ ]
4238+
&& !(arg instanceof NullLiteral) // unless it's null
4239+
&& (!(atype = arg.resolveTypeBinding()).isArray() // otherwise if it is not an array
4240+
|| !atype.getComponentType().isAssignmentCompatible(paramType.getComponentType().getErasure())
4241+
)
4242+
// or it is not compatible
4243+
) {
42324244
buffer.append("[");
4245+
//
4246+
//
4247+
// bufferDebug(paramType.getComponentType().getName() + " "
4248+
// + (atype != null && atype.isArray() ? atype.getComponentType().getName() : null)
4249+
// + " " + (atype != null && atype.isArray() ? atype.getComponentType().isAssignmentCompatible(paramType.getComponentType()) : null)
4250+
// + " " + (atype != null && atype.isArray() ? paramType.getComponentType().isAssignmentCompatible(atype.getComponentType()) : null)
4251+
// + " " + paramType.getComponentType().getErasure().getName()
4252+
// + " " + paramType.getComponentType().getName()
4253+
// + " " + (atype != null && atype.isArray() ? atype.getComponentType().isAssignmentCompatible(paramType.getComponentType().getErasure()) : null)
4254+
// );
4255+
4256+
42334257
for (int j = i; j < argCount; j++) {
42344258
addExpressionAsTargetType((Expression) arguments.get(j), paramType, op, null);
42354259
if (j != argCount - 1) {
@@ -5391,8 +5415,8 @@ private String getParamsAsString(int nParams, String[] genericTypes, ITypeBindin
53915415
String genericType = genericTypes[i];
53925416
if (genericType != null) {
53935417
boolean isAlias = (genericType.indexOf("|") < 0);
5394-
if (isAlias)
5395-
bufferDebug(genericType + " " + i + " " + nParams);
5418+
// if (isAlias)
5419+
// bufferDebug(genericType + " " + i + " " + nParams);
53965420
if (isAlias ? genericType.length() > 0 && !genericType.equals("*")
53975421
: genericType.indexOf("|null") < 0) {
53985422
if (!isAlias && genericType.indexOf("|" + getJavaClassNameQualified(paramTypes[i]) + ";") < 0)

0 commit comments

Comments
 (0)