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) {
|
||||
ifThen(not(genInstanceOf(srcArg, dstClass))) {
|
||||
if (dstClass.defaultType.isObjCObjectType()) {
|
||||
val dstFullClassName = dstClass.fqNameWhenAvailable?.toString() ?: dstClass.name.toString()
|
||||
callDirect(
|
||||
context.ir.symbols.throwTypeCastException.owner,
|
||||
emptyList(),
|
||||
listOf(srcArg, context.llvm.staticData.kotlinStringLiteral(dstFullClassName).llvm),
|
||||
Lifetime.GLOBAL,
|
||||
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
|
||||
fun ThrowTypeCastException(): Nothing {
|
||||
throw TypeCastException()
|
||||
fun ThrowTypeCastException(instance: Any, typeName: String): Nothing {
|
||||
throw TypeCastException("${instance::class} cannot be cast to class $typeName")
|
||||
}
|
||||
|
||||
@ExportForCppRuntime
|
||||
|
||||
Reference in New Issue
Block a user