From 47fec6c9d518982952bda9e3347ddae732ad5d16 Mon Sep 17 00:00:00 2001 From: Mikhael Bogdanov Date: Thu, 18 May 2017 16:20:47 +0200 Subject: [PATCH] Wrap captured local delegated property into Delegate #KT-16864 Fixed --- .../kotlin/codegen/ExpressionCodegen.java | 2 +- .../box/delegatedProperty/local/kt16864.kt | 13 +++++++++++ .../boxInline/delegatedProperty/kt16864.kt | 23 +++++++++++++++++++ .../ir/IrBlackBoxCodegenTestGenerated.java | 6 +++++ .../codegen/BlackBoxCodegenTestGenerated.java | 6 +++++ .../BlackBoxInlineCodegenTestGenerated.java | 6 +++++ ...otlinAgainstInlineKotlinTestGenerated.java | 6 +++++ .../LightAnalysisModeTestGenerated.java | 6 +++++ .../semantics/JsCodegenBoxTestGenerated.java | 6 +++++ 9 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/codegen/box/delegatedProperty/local/kt16864.kt create mode 100644 compiler/testData/codegen/boxInline/delegatedProperty/kt16864.kt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java index 8a883d334d2..57a3eb15c0e 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java @@ -1740,7 +1740,7 @@ public class ExpressionCodegen extends KtVisitor impleme int parameterOffsetInConstructor = context.closure.getCapturedParameterOffsetInConstructor(descriptor); // when captured parameter is singleton // see compiler/testData/codegen/box/objects/objectInLocalAnonymousObject.kt (fun local() captured in A) - if (parameterOffsetInConstructor == -1) return parentResult; + if (parameterOffsetInConstructor == -1) return adjustVariableValue(parentResult , descriptor); assert parentResult instanceof StackValue.Field || parentResult instanceof StackValue.FieldForSharedVar : "Part of closure should be either Field or FieldForSharedVar"; diff --git a/compiler/testData/codegen/box/delegatedProperty/local/kt16864.kt b/compiler/testData/codegen/box/delegatedProperty/local/kt16864.kt new file mode 100644 index 00000000000..99b3011a5c4 --- /dev/null +++ b/compiler/testData/codegen/box/delegatedProperty/local/kt16864.kt @@ -0,0 +1,13 @@ + +object Whatever { + operator fun getValue(thisRef: Any?, prop: Any?) = "OK" +} + +fun box(): String { + val key by Whatever + return { + object { + val keys = key + }.keys + } () +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxInline/delegatedProperty/kt16864.kt b/compiler/testData/codegen/boxInline/delegatedProperty/kt16864.kt new file mode 100644 index 00000000000..0261b5f3b00 --- /dev/null +++ b/compiler/testData/codegen/boxInline/delegatedProperty/kt16864.kt @@ -0,0 +1,23 @@ +// FILE: 1.kt +package test + + +inline fun mrun(lambda: () -> T): T = lambda() + + +// FILE: 2.kt +// NO_CHECK_LAMBDA_INLINING +import test.* + +object Whatever { + operator fun getValue(thisRef: Any?, prop: Any?) = "OK" +} + +fun box(): String { + val key by Whatever + return mrun { + object { + val keys = key + }.keys + } +} \ No newline at end of file diff --git a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 0ea5ec5aed2..c956fb28853 100644 --- a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -6847,6 +6847,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes doTest(fileName); } + @TestMetadata("kt16864.kt") + public void testKt16864() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/delegatedProperty/local/kt16864.kt"); + doTest(fileName); + } + @TestMetadata("localVal.kt") public void testLocalVal() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/delegatedProperty/local/localVal.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 8621799785e..7ce1e888df6 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -6847,6 +6847,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } + @TestMetadata("kt16864.kt") + public void testKt16864() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/delegatedProperty/local/kt16864.kt"); + doTest(fileName); + } + @TestMetadata("localVal.kt") public void testLocalVal() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/delegatedProperty/local/localVal.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java index 09a2fcc2128..dbdc6027571 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java @@ -1199,6 +1199,12 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/delegatedProperty"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); } + @TestMetadata("kt16864.kt") + public void testKt16864() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/delegatedProperty/kt16864.kt"); + doTest(fileName); + } + @TestMetadata("local.kt") public void testLocal() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/delegatedProperty/local.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java index 452d2b642c2..9d1ac31d9f0 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java @@ -1199,6 +1199,12 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/delegatedProperty"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); } + @TestMetadata("kt16864.kt") + public void testKt16864() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/delegatedProperty/kt16864.kt"); + doTest(fileName); + } + @TestMetadata("local.kt") public void testLocal() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/delegatedProperty/local.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index d481d2483e3..39c706a3451 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -6847,6 +6847,12 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes doTest(fileName); } + @TestMetadata("kt16864.kt") + public void testKt16864() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/delegatedProperty/local/kt16864.kt"); + doTest(fileName); + } + @TestMetadata("localVal.kt") public void testLocalVal() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/delegatedProperty/local/localVal.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index 022d92368e9..5b0cbc9f66a 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -7645,6 +7645,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { doTest(fileName); } + @TestMetadata("kt16864.kt") + public void testKt16864() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/delegatedProperty/local/kt16864.kt"); + doTest(fileName); + } + @TestMetadata("localVal.kt") public void testLocalVal() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/delegatedProperty/local/localVal.kt");