Fix kotlinFunction for inline reified methods in reflection
Inline functions with reified type parameters are generated as private (see AsmUtil.specialCaseVisibility), so we should treat them as "declared" in reflection to look them up via getDeclaredMethod, not getMethod #KT-14721 Fixed
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
// IGNORE_BACKEND: JS
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.*
|
||||
import kotlin.reflect.jvm.*
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
inline fun <reified T> f() = 1
|
||||
|
||||
fun g() {}
|
||||
|
||||
class Foo {
|
||||
inline fun <reified T> h(t: T) = 1
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(::g, ::g.javaMethod!!.kotlinFunction)
|
||||
|
||||
val h = Foo::class.members.single { it.name == "h" } as KFunction<*>
|
||||
assertEquals(h, h.javaMethod!!.kotlinFunction)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
public final class Foo {
|
||||
public method <init>(): void
|
||||
private final method h(p0: java.lang.Object): int
|
||||
}
|
||||
|
||||
|
||||
public final class InlineReifiedFunKt {
|
||||
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
|
||||
private final static method f(): int
|
||||
public final static method g(): void
|
||||
}
|
||||
+6
@@ -13492,6 +13492,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("inlineReifiedFun.kt")
|
||||
public void testInlineReifiedFun() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reflection/mapping/inlineReifiedFun.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("mappedClassIsEqualToClassLiteral.kt")
|
||||
public void testMappedClassIsEqualToClassLiteral() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reflection/mapping/mappedClassIsEqualToClassLiteral.kt");
|
||||
|
||||
@@ -13492,6 +13492,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("inlineReifiedFun.kt")
|
||||
public void testInlineReifiedFun() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reflection/mapping/inlineReifiedFun.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("mappedClassIsEqualToClassLiteral.kt")
|
||||
public void testMappedClassIsEqualToClassLiteral() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reflection/mapping/mappedClassIsEqualToClassLiteral.kt");
|
||||
|
||||
@@ -13492,6 +13492,12 @@ public class LightAnalysisModeCodegenTestGenerated extends AbstractLightAnalysis
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("inlineReifiedFun.kt")
|
||||
public void testInlineReifiedFun() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reflection/mapping/inlineReifiedFun.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("mappedClassIsEqualToClassLiteral.kt")
|
||||
public void testMappedClassIsEqualToClassLiteral() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reflection/mapping/mappedClassIsEqualToClassLiteral.kt");
|
||||
|
||||
Reference in New Issue
Block a user