Fix reflection class lookup in default package
Do not append "." to the name of the class in the default package.
This commit is contained in:
committed by
Space Team
parent
e290fa5f7b
commit
51ce829b96
+6
@@ -41679,6 +41679,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
|||||||
runTest("compiler/testData/codegen/box/reflection/annotations/onTypes/arrayKClass.kt");
|
runTest("compiler/testData/codegen/box/reflection/annotations/onTypes/arrayKClass.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("arrayTypeInDefaultPackage.kt")
|
||||||
|
public void testArrayTypeInDefaultPackage() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/reflection/annotations/onTypes/arrayTypeInDefaultPackage.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("classLiteralWithExpectedType.kt")
|
@TestMetadata("classLiteralWithExpectedType.kt")
|
||||||
public void testClassLiteralWithExpectedType() throws Exception {
|
public void testClassLiteralWithExpectedType() throws Exception {
|
||||||
|
|||||||
+20
@@ -0,0 +1,20 @@
|
|||||||
|
// TARGET_BACKEND: JVM
|
||||||
|
// WITH_REFLECT
|
||||||
|
|
||||||
|
import kotlin.reflect.KClass
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
|
annotation class Nested(val value: String)
|
||||||
|
|
||||||
|
@Target(AnnotationTarget.TYPE)
|
||||||
|
annotation class Anno(
|
||||||
|
val aa: Array<Nested>,
|
||||||
|
)
|
||||||
|
|
||||||
|
fun f(): @Anno([Nested("OK")]) Unit {}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val anno = ::f.returnType.annotations.single() as Anno
|
||||||
|
return anno.aa[0].value
|
||||||
|
}
|
||||||
+6
@@ -40245,6 +40245,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
runTest("compiler/testData/codegen/box/reflection/annotations/onTypes/arrayKClass.kt");
|
runTest("compiler/testData/codegen/box/reflection/annotations/onTypes/arrayKClass.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("arrayTypeInDefaultPackage.kt")
|
||||||
|
public void testArrayTypeInDefaultPackage() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/reflection/annotations/onTypes/arrayTypeInDefaultPackage.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("classLiteralWithExpectedType.kt")
|
@TestMetadata("classLiteralWithExpectedType.kt")
|
||||||
public void testClassLiteralWithExpectedType() throws Exception {
|
public void testClassLiteralWithExpectedType() throws Exception {
|
||||||
|
|||||||
+6
@@ -41679,6 +41679,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
runTest("compiler/testData/codegen/box/reflection/annotations/onTypes/arrayKClass.kt");
|
runTest("compiler/testData/codegen/box/reflection/annotations/onTypes/arrayKClass.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("arrayTypeInDefaultPackage.kt")
|
||||||
|
public void testArrayTypeInDefaultPackage() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/reflection/annotations/onTypes/arrayTypeInDefaultPackage.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("classLiteralWithExpectedType.kt")
|
@TestMetadata("classLiteralWithExpectedType.kt")
|
||||||
public void testClassLiteralWithExpectedType() throws Exception {
|
public void testClassLiteralWithExpectedType() throws Exception {
|
||||||
|
|||||||
+5
@@ -32100,6 +32100,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
runTest("compiler/testData/codegen/box/reflection/annotations/onTypes/arrayKClass.kt");
|
runTest("compiler/testData/codegen/box/reflection/annotations/onTypes/arrayKClass.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("arrayTypeInDefaultPackage.kt")
|
||||||
|
public void testArrayTypeInDefaultPackage() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/reflection/annotations/onTypes/arrayTypeInDefaultPackage.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("classLiteralWithExpectedType.kt")
|
@TestMetadata("classLiteralWithExpectedType.kt")
|
||||||
public void testClassLiteralWithExpectedType() throws Exception {
|
public void testClassLiteralWithExpectedType() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/reflection/annotations/onTypes/classLiteralWithExpectedType.kt");
|
runTest("compiler/testData/codegen/box/reflection/annotations/onTypes/classLiteralWithExpectedType.kt");
|
||||||
|
|||||||
@@ -97,9 +97,20 @@ private fun loadClass(classLoader: ClassLoader, packageName: String, className:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var fqName = "$packageName.${className.replace('.', '$')}"
|
val fqName = buildString {
|
||||||
if (arrayDimensions > 0) {
|
if (arrayDimensions > 0) {
|
||||||
fqName = "[".repeat(arrayDimensions) + "L$fqName;"
|
repeat(arrayDimensions) {
|
||||||
|
append("[")
|
||||||
|
}
|
||||||
|
append("L")
|
||||||
|
}
|
||||||
|
if (packageName.isNotEmpty()) {
|
||||||
|
append("$packageName.")
|
||||||
|
}
|
||||||
|
append(className.replace('.', '$'))
|
||||||
|
if (arrayDimensions > 0) {
|
||||||
|
append(";")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return classLoader.tryLoadClass(fqName)
|
return classLoader.tryLoadClass(fqName)
|
||||||
|
|||||||
Reference in New Issue
Block a user