diff --git a/runtime/src/main/cpp/Exceptions.h b/runtime/src/main/cpp/Exceptions.h index 654b5c4364d..0ee9b6bee15 100644 --- a/runtime/src/main/cpp/Exceptions.h +++ b/runtime/src/main/cpp/Exceptions.h @@ -39,7 +39,7 @@ void RUNTIME_NORETURN ThrowNullPointerException(); // Context is evaluated from caller's address. void RUNTIME_NORETURN ThrowArrayIndexOutOfBoundsException(); // Throws class cast exception. -void RUNTIME_NORETURN ThrowClassCastException(); +void RUNTIME_NORETURN ThrowClassCastException(const ObjHeader* instance, const TypeInfo* type_info); // Throws arithmetic exception. void RUNTIME_NORETURN ThrowArithmeticException(); // Throws number format exception. diff --git a/runtime/src/main/cpp/Types.cpp b/runtime/src/main/cpp/Types.cpp index 2ca4e6e67e4..b5d84d94826 100644 --- a/runtime/src/main/cpp/Types.cpp +++ b/runtime/src/main/cpp/Types.cpp @@ -47,7 +47,7 @@ void CheckInstance(const ObjHeader* obj, const TypeInfo* type_info) { if (IsInstance(obj, type_info)) { return; } - ThrowClassCastException(); + ThrowClassCastException(obj, type_info); } KBoolean Kotlin_TypeInfo_isInstance(KConstRef obj, KNativePtr typeInfo) { diff --git a/runtime/src/main/kotlin/konan/internal/RuntimeUtils.kt b/runtime/src/main/kotlin/konan/internal/RuntimeUtils.kt index 899420a93de..9beba050415 100644 --- a/runtime/src/main/kotlin/konan/internal/RuntimeUtils.kt +++ b/runtime/src/main/kotlin/konan/internal/RuntimeUtils.kt @@ -30,8 +30,9 @@ internal fun ThrowArrayIndexOutOfBoundsException(): Nothing { } @ExportForCppRuntime -fun ThrowClassCastException(): Nothing { - throw ClassCastException() +fun ThrowClassCastException(instance: Any, typeInfo: NativePtr): Nothing { + val clazz = KClassImpl(typeInfo) + throw ClassCastException("${instance::class.qualifiedName} cannot be cast to ${clazz.qualifiedName}") } fun ThrowTypeCastException(): Nothing {