Merge pull request #132 from codecop/master
Contribution from Hackergarten Vienna: fixed KT-2892 'No such field error' when invoking private property without backing field #KT-2892 Fixed
This commit is contained in:
@@ -750,7 +750,8 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
InstructionAdapter iv = new InstructionAdapter(mv);
|
InstructionAdapter iv = new InstructionAdapter(mv);
|
||||||
|
|
||||||
iv.load(0, OBJECT_TYPE);
|
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(),
|
iv.getfield(typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION).getInternalName(), original.getName().getName(),
|
||||||
originalMethod.getReturnType().getDescriptor());
|
originalMethod.getReturnType().getDescriptor());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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"
|
||||||
@@ -360,4 +360,10 @@ public class PropertyGenTest extends CodegenTestCase {
|
|||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testKt2892() throws Exception {
|
||||||
|
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
|
||||||
|
blackBoxFile("properties/kt2892.kt");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user