Fix "kotlin.TypeCastException has no message on Native"
#KT-35544 Fixed Merge-request: KT-MR-6392 Merged-by: Vladimir Sukharev <Vladimir.Sukharev@jetbrains.com>
This commit is contained in:
+2
-1
@@ -1556,9 +1556,10 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
|
|||||||
with(functionGenerationContext) {
|
with(functionGenerationContext) {
|
||||||
ifThen(not(genInstanceOf(srcArg, dstClass))) {
|
ifThen(not(genInstanceOf(srcArg, dstClass))) {
|
||||||
if (dstClass.defaultType.isObjCObjectType()) {
|
if (dstClass.defaultType.isObjCObjectType()) {
|
||||||
|
val dstFullClassName = dstClass.fqNameWhenAvailable?.toString() ?: dstClass.name.toString()
|
||||||
callDirect(
|
callDirect(
|
||||||
context.ir.symbols.throwTypeCastException.owner,
|
context.ir.symbols.throwTypeCastException.owner,
|
||||||
emptyList(),
|
listOf(srcArg, context.llvm.staticData.kotlinStringLiteral(dstFullClassName).llvm),
|
||||||
Lifetime.GLOBAL,
|
Lifetime.GLOBAL,
|
||||||
null
|
null
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import kotlin.test.*
|
||||||
|
import objcTests.*
|
||||||
|
@Test
|
||||||
|
fun testKT35544() {
|
||||||
|
val exception = assertFailsWith<TypeCastException> {
|
||||||
|
123 as NSString
|
||||||
|
}
|
||||||
|
assertEquals("class kotlin.Int cannot be cast to class objcTests.NSString", exception.message)
|
||||||
|
}
|
||||||
@@ -32,8 +32,8 @@ fun ThrowClassCastException(instance: Any, typeInfo: NativePtr): Nothing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ExportForCppRuntime
|
@ExportForCppRuntime
|
||||||
fun ThrowTypeCastException(): Nothing {
|
fun ThrowTypeCastException(instance: Any, typeName: String): Nothing {
|
||||||
throw TypeCastException()
|
throw TypeCastException("${instance::class} cannot be cast to class $typeName")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ExportForCppRuntime
|
@ExportForCppRuntime
|
||||||
|
|||||||
Reference in New Issue
Block a user