Coerce any type to Number before unboxing
This commit is contained in:
@@ -294,16 +294,14 @@ public abstract class StackValue {
|
||||
}
|
||||
}
|
||||
else if (fromType.getSort() == Type.OBJECT && toType.getSort() <= Type.DOUBLE) {
|
||||
if (fromType.equals(OBJECT_TYPE)) {
|
||||
if (toType.getSort() == Type.BOOLEAN) {
|
||||
v.checkcast(JvmPrimitiveType.BOOLEAN.getWrapper().getAsmType());
|
||||
}
|
||||
else if (toType.getSort() == Type.CHAR) {
|
||||
v.checkcast(JvmPrimitiveType.CHAR.getWrapper().getAsmType());
|
||||
}
|
||||
else {
|
||||
v.checkcast(getType(Number.class));
|
||||
}
|
||||
if (toType.getSort() == Type.BOOLEAN) {
|
||||
coerce(fromType, JvmPrimitiveType.BOOLEAN.getWrapper().getAsmType(), v);
|
||||
}
|
||||
else if (toType.getSort() == Type.CHAR) {
|
||||
coerce(fromType, JvmPrimitiveType.CHAR.getWrapper().getAsmType(), v);
|
||||
}
|
||||
else {
|
||||
coerce(fromType, getType(Number.class), v);
|
||||
}
|
||||
unbox(toType, v);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
fun foo(x: Int) = x
|
||||
|
||||
fun bar(x: Comparable<Int>) = if (x is Int) foo(x) else 0
|
||||
|
||||
fun box() = if (bar(42) == 42) "OK" else "Fail"
|
||||
@@ -456,4 +456,8 @@ public class PrimitiveTypesTest extends CodegenTestCase {
|
||||
public void test2794() throws Exception {
|
||||
blackBoxFile("regressions/kt2794.kt");
|
||||
}
|
||||
|
||||
public void testUnboxComparable() {
|
||||
blackBoxFile("primitiveTypes/unboxComparable.kt");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user