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:
Svyatoslav Scherbina
2022-03-18 17:50:57 +03:00
committed by Space
parent 5c612078e5
commit cf581738c3
13 changed files with 191 additions and 1 deletions
@@ -3738,6 +3738,42 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest
runTest("compiler/testData/codegen/box/casts/mutableCollections/weirdMutableCasts.kt");
}
}
@Nested
@TestMetadata("compiler/testData/codegen/box/casts/nativeCCEMessage")
@TestDataPath("$PROJECT_ROOT")
@Tag("codegen")
@UseExtTestCaseGroupProvider()
public class NativeCCEMessage {
@Test
public void testAllFilesPresentInNativeCCEMessage() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/casts/nativeCCEMessage"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.NATIVE, true);
}
@Test
@TestMetadata("castAnonymousClass.kt")
public void testCastAnonymousClass() throws Exception {
runTest("compiler/testData/codegen/box/casts/nativeCCEMessage/castAnonymousClass.kt");
}
@Test
@TestMetadata("castGlobalClass.kt")
public void testCastGlobalClass() throws Exception {
runTest("compiler/testData/codegen/box/casts/nativeCCEMessage/castGlobalClass.kt");
}
@Test
@TestMetadata("castLocalClass.kt")
public void testCastLocalClass() throws Exception {
runTest("compiler/testData/codegen/box/casts/nativeCCEMessage/castLocalClass.kt");
}
@Test
@TestMetadata("castToLocalClass.kt")
public void testCastToLocalClass() throws Exception {
runTest("compiler/testData/codegen/box/casts/nativeCCEMessage/castToLocalClass.kt");
}
}
}
@Nested