Native: improve ClassCastException message for local classes
Previously it was like "null cannot be cast to MyObject" or "MyObject cannot be cast to null", because `KClass.qualifiedName` is `null` for local classes (including anonymous ones). Use `KClass.toString()` instead, for both object actual dynamic type and cast target type. This string representation is generally more meaningful for such cases, and contains useful details for local classes.
This commit is contained in:
committed by
Space
parent
5c612078e5
commit
cf581738c3
@@ -0,0 +1,20 @@
|
||||
// TARGET_BACKEND: NATIVE
|
||||
|
||||
class MyObject
|
||||
|
||||
// Test infrastructure can move declarations to a package. So we need a prefix for class names in exception messages:
|
||||
val p = MyObject::class.qualifiedName!!.removeSuffix("MyObject")
|
||||
|
||||
fun box(): String {
|
||||
class MyLocalObject
|
||||
try {
|
||||
MyObject() as MyLocalObject
|
||||
} catch (e: Throwable) {
|
||||
if (e !is ClassCastException) return "fail 1: $e"
|
||||
if (e.message != "class ${p}MyObject cannot be cast to class ${p}box\$MyLocalObject") return "fail 2: ${e.message}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
return "fail 3"
|
||||
}
|
||||
Reference in New Issue
Block a user