Fix for KT-16732: Type 'java/lang/Number' (current frame, stack[0]) is not assignable to 'java/lang/Character
#KT-16732 Fixed
This commit is contained in:
@@ -48,6 +48,7 @@ import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterSignature
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.org.objectweb.asm.Label;
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes;
|
||||
import org.jetbrains.org.objectweb.asm.Type;
|
||||
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter;
|
||||
|
||||
@@ -381,14 +382,22 @@ public abstract class StackValue {
|
||||
unbox(unboxedType, v);
|
||||
coerce(unboxedType, toType, v);
|
||||
}
|
||||
else {
|
||||
Type numberType = getType(Number.class);
|
||||
if (toType.getSort() == Type.BOOLEAN || (toType.getSort() == Type.CHAR && !numberType.equals(fromType))) {
|
||||
coerce(fromType, boxType(toType), v);
|
||||
else if (toType.getSort() == Type.BOOLEAN) {
|
||||
coerce(fromType, boxType(Type.BOOLEAN_TYPE), v);
|
||||
unbox(Type.BOOLEAN_TYPE, v);
|
||||
}
|
||||
else if (toType.getSort() == Type.CHAR) {
|
||||
if (fromType.equals(NUMBER_TYPE)) {
|
||||
unbox(Type.INT_TYPE, v);
|
||||
v.visitInsn(Opcodes.I2C);
|
||||
}
|
||||
else {
|
||||
coerce(fromType, numberType, v);
|
||||
coerce(fromType, boxType(Type.CHAR_TYPE), v);
|
||||
unbox(Type.CHAR_TYPE, v);
|
||||
}
|
||||
}
|
||||
else {
|
||||
coerce(fromType, NUMBER_TYPE, v);
|
||||
unbox(toType, v);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ public class AsmTypes {
|
||||
public static final Type JAVA_THROWABLE_TYPE = getType(Throwable.class);
|
||||
public static final Type JAVA_CLASS_TYPE = getType(Class.class);
|
||||
public static final Type ENUM_TYPE = getType(Enum.class);
|
||||
public static final Type NUMBER_TYPE = getType(Number.class);
|
||||
|
||||
public static final Type UNIT_TYPE = Type.getObjectType("kotlin/Unit");
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
//WITH_RUNTIME
|
||||
|
||||
fun valueFromDB(value: Any): Any {
|
||||
return when (value) {
|
||||
is Char -> value
|
||||
is Number-> value.toChar()
|
||||
is String -> value.single()
|
||||
else -> error("Unexpected value of type Char: $value")
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
valueFromDB(1)
|
||||
return "" + valueFromDB("O") + valueFromDB("K")
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
@kotlin.Metadata
|
||||
public final class Kt16732Kt {
|
||||
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
|
||||
public final static @org.jetbrains.annotations.NotNull method valueFromDB(@org.jetbrains.annotations.NotNull p0: java.lang.Object): java.lang.Object
|
||||
}
|
||||
+6
@@ -11711,6 +11711,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt16732.kt")
|
||||
public void testKt16732() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/primitiveTypes/kt16732.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt2251.kt")
|
||||
public void testKt2251() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/primitiveTypes/kt2251.kt");
|
||||
|
||||
@@ -11711,6 +11711,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt16732.kt")
|
||||
public void testKt16732() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/primitiveTypes/kt16732.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt2251.kt")
|
||||
public void testKt2251() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/primitiveTypes/kt2251.kt");
|
||||
|
||||
@@ -13183,6 +13183,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt16732.kt")
|
||||
public void testKt16732() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/primitiveTypes/kt16732.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt2251.kt")
|
||||
public void testKt2251() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/primitiveTypes/kt2251.kt");
|
||||
|
||||
Reference in New Issue
Block a user