From 28160ecb11451934ee7c7c524cf2a055563b2e0b Mon Sep 17 00:00:00 2001 From: Peter Kofler Date: Mon, 29 Oct 2012 22:10:00 +0100 Subject: [PATCH] fix KT-2892 --- .../jet/codegen/ImplementationBodyCodegen.java | 3 ++- compiler/testData/codegen/properties/kt2892.kt | 16 ++++++++++++++++ .../jetbrains/jet/codegen/PropertyGenTest.java | 6 ++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/codegen/properties/kt2892.kt diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java index b0af3b142da..26a482ee292 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java @@ -750,7 +750,8 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { InstructionAdapter iv = new InstructionAdapter(mv); iv.load(0, OBJECT_TYPE); - if (original.getVisibility() == Visibilities.PRIVATE) { + boolean hasBackingField = Boolean.TRUE.equals(bindingContext.get(BindingContext.BACKING_FIELD_REQUIRED, original)); + if (original.getVisibility() == Visibilities.PRIVATE && hasBackingField) { iv.getfield(typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION).getInternalName(), original.getName().getName(), originalMethod.getReturnType().getDescriptor()); } diff --git a/compiler/testData/codegen/properties/kt2892.kt b/compiler/testData/codegen/properties/kt2892.kt new file mode 100644 index 00000000000..816b11009d7 --- /dev/null +++ b/compiler/testData/codegen/properties/kt2892.kt @@ -0,0 +1,16 @@ +open class A +class B : A() { + fun foo() = 1 +} + +class Test { + val a : A = B() + private val b : B get() = a as B //'private' is important here + + fun outer() : Int { + fun inner() : Int = b.foo() //'no such field error' here + return inner() + } +} + +fun box() = if (Test().outer() == 1) "OK" else "fail" diff --git a/compiler/tests/org/jetbrains/jet/codegen/PropertyGenTest.java b/compiler/tests/org/jetbrains/jet/codegen/PropertyGenTest.java index 543fc116893..25b4737f392 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/PropertyGenTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/PropertyGenTest.java @@ -360,4 +360,10 @@ public class PropertyGenTest extends CodegenTestCase { throw new RuntimeException(e); } } + + public void testKt2892() throws Exception { + createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY); + blackBoxFile("properties/kt2892.kt"); + } + }