Fix ClassCastException with nullable chars

#KT-4210 Fixed
 #KT-4098 Fixed
 #KT-4251 Fixed
This commit is contained in:
Alexander Udalov
2013-12-02 23:34:32 +04:00
parent dab9d69a40
commit fa7076a4fa
6 changed files with 70 additions and 4 deletions
@@ -251,13 +251,19 @@ public abstract class StackValue {
}
}
else if (fromType.getSort() == Type.OBJECT) {
if (toType.getSort() == Type.BOOLEAN || toType.getSort() == Type.CHAR) {
coerce(fromType, boxType(toType), v);
if (fromType.equals(getType(Boolean.class)) || fromType.equals(getType(Character.class))) {
unbox(unboxType(fromType), v);
coerce(unboxType(fromType), toType, v);
}
else {
coerce(fromType, getType(Number.class), v);
if (toType.getSort() == Type.BOOLEAN || toType.getSort() == Type.CHAR) {
coerce(fromType, boxType(toType), v);
}
else {
coerce(fromType, getType(Number.class), v);
}
unbox(toType, v);
}
unbox(toType, v);
}
else {
v.cast(fromType, toType);
@@ -0,0 +1,10 @@
fun box(): String {
val c = '0': Char?
c!!.toInt()
"123456"?.get(0)!!.toInt()
"123456"!!.get(0).toInt()
return "OK"
}
@@ -0,0 +1,16 @@
fun box(): String {
val s: String? = "abc"
val c = s?.get(0)!! - 'b'
if (c != -1) return "Fail c: $c"
val d = 'b' - s?.get(2)!!
if (d != -1) return "Fail d: $d"
val e = s?.get(2)!! - s?.get(0)!!
if (e != 2) return "Fail e: $e"
val f = s?.get(2)!!.minus(s?.get(0)!!)
if (f != 2) return "Fail f: $f"
return "OK"
}
@@ -0,0 +1,5 @@
fun box(): String {
val a: Char? = 'a'
val result = a!! < 'b'
return if (result) "OK" else "Fail"
}
@@ -0,0 +1,9 @@
fun box(): String {
val c: Char? = 'a'
if (c!! - 'a' != 0) return "Fail c"
val b: Boolean? = false
if (b!!) return "Fail b"
return "OK"
}
@@ -3807,6 +3807,21 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
doTest("compiler/testData/codegen/box/primitiveTypes/kt3576.kt");
}
@TestMetadata("kt4098.kt")
public void testKt4098() throws Exception {
doTest("compiler/testData/codegen/box/primitiveTypes/kt4098.kt");
}
@TestMetadata("kt4210.kt")
public void testKt4210() throws Exception {
doTest("compiler/testData/codegen/box/primitiveTypes/kt4210.kt");
}
@TestMetadata("kt4251.kt")
public void testKt4251() throws Exception {
doTest("compiler/testData/codegen/box/primitiveTypes/kt4251.kt");
}
@TestMetadata("kt446.kt")
public void testKt446() throws Exception {
doTest("compiler/testData/codegen/box/primitiveTypes/kt446.kt");
@@ -3892,6 +3907,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
doTest("compiler/testData/codegen/box/primitiveTypes/nullAsNullableIntIsNull.kt");
}
@TestMetadata("nullableCharBoolean.kt")
public void testNullableCharBoolean() throws Exception {
doTest("compiler/testData/codegen/box/primitiveTypes/nullableCharBoolean.kt");
}
@TestMetadata("unboxComparable.kt")
public void testUnboxComparable() throws Exception {
doTest("compiler/testData/codegen/box/primitiveTypes/unboxComparable.kt");