diff --git a/compiler/testData/codegen/boxWithJava/reflection/callPrivateJavaMethod/J.java b/compiler/testData/codegen/boxWithJava/reflection/callPrivateJavaMethod/J.java new file mode 100644 index 00000000000..55a31a8667d --- /dev/null +++ b/compiler/testData/codegen/boxWithJava/reflection/callPrivateJavaMethod/J.java @@ -0,0 +1,11 @@ +public class J { + private final String result; + + private J(String result) { + this.result = result; + } + + private String getResult() { + return result; + } +} diff --git a/compiler/testData/codegen/boxWithJava/reflection/callPrivateJavaMethod/K.kt b/compiler/testData/codegen/boxWithJava/reflection/callPrivateJavaMethod/K.kt new file mode 100644 index 00000000000..5a5fb8f9dfa --- /dev/null +++ b/compiler/testData/codegen/boxWithJava/reflection/callPrivateJavaMethod/K.kt @@ -0,0 +1,20 @@ +import kotlin.reflect.* +import kotlin.reflect.jvm.* +import kotlin.test.* + +fun box(): String { + val c = J::class.constructors.single() + assertFalse(c.isAccessible) + failsWith(javaClass()) { c.call("") } + + c.isAccessible = true + assertTrue(c.isAccessible) + val j = c.call("OK") + + val m = J::class.members.single { it.name == "getResult" } + assertFalse(m.isAccessible) + failsWith(javaClass()) { m.call(j)!! } + + m.isAccessible = true + return m.call(j) as String +} diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/call/fakeOverride.kt b/compiler/testData/codegen/boxWithStdlib/reflection/call/fakeOverride.kt new file mode 100644 index 00000000000..dbcb0b39d1a --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/reflection/call/fakeOverride.kt @@ -0,0 +1,10 @@ +open class A { + fun foo() = "OK" +} + +class B : A() + +fun box(): String { + val foo = B::class.members.single { it.name == "foo" } + return foo.call(B()) as String +} diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/call/fakeOverrideSubstituted.kt b/compiler/testData/codegen/boxWithStdlib/reflection/call/fakeOverrideSubstituted.kt new file mode 100644 index 00000000000..506a1a44dee --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/reflection/call/fakeOverrideSubstituted.kt @@ -0,0 +1,10 @@ +open class A(val t: T) { + fun foo() = t +} + +class B(s: String) : A(s) + +fun box(): String { + val foo = B::class.members.single { it.name == "foo" } + return foo.call(B("OK")) as String +} diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/call/localClassMember.kt b/compiler/testData/codegen/boxWithStdlib/reflection/call/localClassMember.kt new file mode 100644 index 00000000000..115b402b794 --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/reflection/call/localClassMember.kt @@ -0,0 +1,7 @@ +fun box(): String { + class Local { + fun result(s: String) = s + } + + return Local::result.call(Local(), "OK") +} diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithJavaCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithJavaCodegenTestGenerated.java index aefdc3fd4f7..89c609f3b16 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithJavaCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithJavaCodegenTestGenerated.java @@ -273,6 +273,12 @@ public class BlackBoxWithJavaCodegenTestGenerated extends AbstractBlackBoxCodege doTestWithJava(fileName); } + @TestMetadata("callPrivateJavaMethod") + public void testCallPrivateJavaMethod() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithJava/reflection/callPrivateJavaMethod/"); + doTestWithJava(fileName); + } + @TestMetadata("callStaticJavaMethod") public void testCallStaticJavaMethod() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithJava/reflection/callStaticJavaMethod/"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java index 28e19e180f0..3fdceb57275 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java @@ -2862,6 +2862,18 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode doTestWithStdlib(fileName); } + @TestMetadata("fakeOverride.kt") + public void testFakeOverride() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/reflection/call/fakeOverride.kt"); + doTestWithStdlib(fileName); + } + + @TestMetadata("fakeOverrideSubstituted.kt") + public void testFakeOverrideSubstituted() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/reflection/call/fakeOverrideSubstituted.kt"); + doTestWithStdlib(fileName); + } + @TestMetadata("incorrectNumberOfArguments.kt") public void testIncorrectNumberOfArguments() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/reflection/call/incorrectNumberOfArguments.kt"); @@ -2874,6 +2886,12 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode doTestWithStdlib(fileName); } + @TestMetadata("localClassMember.kt") + public void testLocalClassMember() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/reflection/call/localClassMember.kt"); + doTestWithStdlib(fileName); + } + @TestMetadata("memberOfGenericClass.kt") public void testMemberOfGenericClass() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/reflection/call/memberOfGenericClass.kt");