Fix problem with empty vararg of boxed primitives in JVM_IR
When calling a generic Java generic method with vararg parameters with empty
vararg, incorrect array creation instruction was generated for primitive type:
NEWARRAY T_INT instead of ANEWARRAY java/lang/Integer. Here for Java method
public static <T> void takesVarargOfT(T x1, T... xs) {}
corresponding vararg parameter was considered to be of type 'Array<T>?',
which is not a non-null array type, so, NewArray intrinsic failed to generate
proper bytecode.
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// FILE: emptyVarargOfBoxedPrimitiveType.kt
|
||||
|
||||
fun box(): String {
|
||||
takesVarargOfInt(1)
|
||||
takesVarargOfT(1)
|
||||
|
||||
J.takesVarargOfInt(1)
|
||||
J.takesVarargOfInteger(1)
|
||||
J.takesVarargOfT(1)
|
||||
|
||||
takesVarargOfInt(1, 2)
|
||||
takesVarargOfT(1, 2)
|
||||
|
||||
J.takesVarargOfInt(1, 2)
|
||||
J.takesVarargOfInteger(1, 2)
|
||||
J.takesVarargOfT(1, 2)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
fun takesVarargOfInt(x: Int, vararg xs: Int) {}
|
||||
fun <T> takesVarargOfT(x: T, vararg xs: T) {}
|
||||
|
||||
// FILE: J.java
|
||||
public class J {
|
||||
public static void takesVarargOfInt(int x1, int... xs) {}
|
||||
|
||||
public static void takesVarargOfInteger(Integer x1, Integer... xs) {}
|
||||
|
||||
public static <T> void takesVarargOfT(T x1, T... xs) {
|
||||
Class<?> x1Class = x1.getClass();
|
||||
Class<?> xsClass = xs.getClass();
|
||||
Class<?> xsComponentClass = xsClass.getComponentType();
|
||||
if (!xsComponentClass.equals(x1Class)) {
|
||||
throw new AssertionError(
|
||||
"Wrong array component type " + xsComponentClass +
|
||||
" for array class " + xsClass +
|
||||
", expected: " + x1Class
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user