From 55d2300860c6a8d7a8fc3e13a1634de90ecf43dd Mon Sep 17 00:00:00 2001 From: Michael Bogdanov Date: Wed, 21 Oct 2015 14:24:31 +0300 Subject: [PATCH] Fix for KT-6722 #KT-6722 Fixed --- .../kotlin/codegen/ImplementationBodyCodegen.java | 2 +- .../boxWithStdlib/delegatedProperty/kt6722.kt | 12 ++++++++++++ .../BlackBoxWithStdlibCodegenTestGenerated.java | 6 ++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/codegen/boxWithStdlib/delegatedProperty/kt6722.kt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java index 1bba7edee86..d814f128a0e 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java @@ -1254,7 +1254,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { for (KtDeclaration declaration : myClass.getDeclarations()) { if (declaration instanceof KtProperty) { KtProperty property = (KtProperty) declaration; - KtExpression initializer = property.getInitializer(); + KtExpression initializer = property.getDelegateExpressionOrInitializer(); if (initializer != null) { initializer.accept(visitor); } diff --git a/compiler/testData/codegen/boxWithStdlib/delegatedProperty/kt6722.kt b/compiler/testData/codegen/boxWithStdlib/delegatedProperty/kt6722.kt new file mode 100644 index 00000000000..2760188b91a --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/delegatedProperty/kt6722.kt @@ -0,0 +1,12 @@ +interface T { +} + +fun box(): String { + val a = "OK" + val t = object : T { + val foo by lazy { + a + } + } + return t.foo +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java index 157c3d24c50..49c0ff1a03f 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java @@ -1456,6 +1456,12 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxWithStdlib/delegatedProperty"), Pattern.compile("^(.+)\\.kt$"), true); } + @TestMetadata("kt6722.kt") + public void testKt6722() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/delegatedProperty/kt6722.kt"); + doTestWithStdlib(fileName); + } + @TestMetadata("stackOverflowOnCallFromGetValue.kt") public void testStackOverflowOnCallFromGetValue() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/delegatedProperty/stackOverflowOnCallFromGetValue.kt");