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) {
|
else if (fromType.getSort() == Type.OBJECT && toType.getSort() <= Type.DOUBLE) {
|
||||||
if (fromType.equals(OBJECT_TYPE)) {
|
if (toType.getSort() == Type.BOOLEAN) {
|
||||||
if (toType.getSort() == Type.BOOLEAN) {
|
coerce(fromType, JvmPrimitiveType.BOOLEAN.getWrapper().getAsmType(), v);
|
||||||
v.checkcast(JvmPrimitiveType.BOOLEAN.getWrapper().getAsmType());
|
}
|
||||||
}
|
else if (toType.getSort() == Type.CHAR) {
|
||||||
else if (toType.getSort() == Type.CHAR) {
|
coerce(fromType, JvmPrimitiveType.CHAR.getWrapper().getAsmType(), v);
|
||||||
v.checkcast(JvmPrimitiveType.CHAR.getWrapper().getAsmType());
|
}
|
||||||
}
|
else {
|
||||||
else {
|
coerce(fromType, getType(Number.class), v);
|
||||||
v.checkcast(getType(Number.class));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
unbox(toType, 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 {
|
public void test2794() throws Exception {
|
||||||
blackBoxFile("regressions/kt2794.kt");
|
blackBoxFile("regressions/kt2794.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testUnboxComparable() {
|
||||||
|
blackBoxFile("primitiveTypes/unboxComparable.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user