From 618468511118ed3fcbffe241eb4692e058db8f29 Mon Sep 17 00:00:00 2001 From: Sergey Bogolepov Date: Thu, 9 Aug 2018 14:27:08 +0300 Subject: [PATCH] Verbose ClassCastException --- runtime/src/main/cpp/Exceptions.h | 2 +- runtime/src/main/cpp/Types.cpp | 2 +- runtime/src/main/kotlin/konan/internal/RuntimeUtils.kt | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) 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 {