diff --git a/compiler/testData/codegen/box/delegatedProperty/useReflectionOnKProperty.kt b/compiler/testData/codegen/box/delegatedProperty/useReflectionOnKProperty.kt new file mode 100644 index 00000000000..006e0a96be4 --- /dev/null +++ b/compiler/testData/codegen/box/delegatedProperty/useReflectionOnKProperty.kt @@ -0,0 +1,14 @@ +import kotlin.reflect.KProperty + +class Delegate { + fun getValue(t: Any?, p: KProperty<*>): String { + p.parameters + p.returnType + p.annotations + return p.toString() + } +} + +val prop: String by Delegate() + +fun box() = if (prop == "val prop: kotlin.String") "OK" else "Fail: $prop" diff --git a/compiler/testData/codegen/boxWithStdlib/delegatedProperty/stackOverflowOnCallFromGetValue.kt b/compiler/testData/codegen/boxWithStdlib/delegatedProperty/stackOverflowOnCallFromGetValue.kt new file mode 100644 index 00000000000..377157f78f4 --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/delegatedProperty/stackOverflowOnCallFromGetValue.kt @@ -0,0 +1,24 @@ +// FULL_JDK + +import kotlin.reflect.KProperty +import kotlin.reflect.KProperty0 +import kotlin.test.assertFailsWith + +class Delegate { + fun getValue(t: Any?, p: KProperty<*>): String { + return (p as KProperty0).get() + } +} + +val prop: String by Delegate() + +fun box(): String { + assertFailsWith( + StackOverflowError::class.java, + "Getting the property value with .get() from getValue is effectively an endless recursion and should fail" + ) { + prop + } + + return "OK" +} diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java index 41ada4c91d5..f9865a8b930 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java @@ -2971,6 +2971,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } + @TestMetadata("useReflectionOnKProperty.kt") + public void testUseReflectionOnKProperty() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/delegatedProperty/useReflectionOnKProperty.kt"); + doTest(fileName); + } + @TestMetadata("valInInnerClass.kt") public void testValInInnerClass() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/delegatedProperty/valInInnerClass.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java index 7f34114fa2a..74ba173df30 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java @@ -1481,6 +1481,21 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode } } + @TestMetadata("compiler/testData/codegen/boxWithStdlib/delegatedProperty") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class DelegatedProperty extends AbstractBlackBoxCodegenTest { + public void testAllFilesPresentInDelegatedProperty() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxWithStdlib/delegatedProperty"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("stackOverflowOnCallFromGetValue.kt") + public void testStackOverflowOnCallFromGetValue() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/delegatedProperty/stackOverflowOnCallFromGetValue.kt"); + doTestWithStdlib(fileName); + } + } + @TestMetadata("compiler/testData/codegen/boxWithStdlib/enum") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)