diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java index 144b7b2ae68..7de2e186ad6 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java @@ -2213,9 +2213,11 @@ public class ExpressionCodegen extends KtVisitor impleme StackValue receiver ) { Type type = typeMapper.mapType(propertyDescriptor.getOriginal().getType()); - CallableMethod callableGetter = typeMapper.mapToCallableMethod(propertyDescriptor.getGetMethod(), false); + CallableMethod callableGetter = + typeMapper.mapToCallableMethod(context.accessibleDescriptor(propertyDescriptor.getGetMethod(), null), false); FunctionDescriptor setMethod = propertyDescriptor.getSetMethod(); - CallableMethod callableSetter = setMethod != null ? typeMapper.mapToCallableMethod(setMethod, false) : null; + CallableMethod callableSetter = + setMethod != null ? typeMapper.mapToCallableMethod(context.accessibleDescriptor(setMethod, null), false) : null; return StackValue.property(propertyDescriptor, null, type, false, null, callableGetter, callableSetter, state, receiver); } diff --git a/compiler/testData/codegen/boxWithJava/properties/protectedJavaProperty/JavaBaseClass.java b/compiler/testData/codegen/boxWithJava/properties/protectedJavaProperty/JavaBaseClass.java new file mode 100644 index 00000000000..d68097f4239 --- /dev/null +++ b/compiler/testData/codegen/boxWithJava/properties/protectedJavaProperty/JavaBaseClass.java @@ -0,0 +1,12 @@ +public class JavaBaseClass { + + private String field = "fail"; + + protected String getFoo() { + return field; + } + + protected void setFoo(String foo) { + field = foo; + } +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxWithJava/properties/protectedJavaProperty/kotlin.kt b/compiler/testData/codegen/boxWithJava/properties/protectedJavaProperty/kotlin.kt new file mode 100644 index 00000000000..bdff5813b26 --- /dev/null +++ b/compiler/testData/codegen/boxWithJava/properties/protectedJavaProperty/kotlin.kt @@ -0,0 +1,19 @@ +package z + +import JavaBaseClass + +object KotlinExtender : JavaBaseClass() { + @JvmStatic fun test(): String { + return runSlowly { + foo = "OK" + foo + } + } +} +fun runSlowly(f: () -> String): String { + return f() +} + +fun box(): String { + return KotlinExtender.test() +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxWithJava/properties/protectedJavaPropertyInCompanion/JavaBaseClass.java b/compiler/testData/codegen/boxWithJava/properties/protectedJavaPropertyInCompanion/JavaBaseClass.java new file mode 100644 index 00000000000..d68097f4239 --- /dev/null +++ b/compiler/testData/codegen/boxWithJava/properties/protectedJavaPropertyInCompanion/JavaBaseClass.java @@ -0,0 +1,12 @@ +public class JavaBaseClass { + + private String field = "fail"; + + protected String getFoo() { + return field; + } + + protected void setFoo(String foo) { + field = foo; + } +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxWithJava/properties/protectedJavaPropertyInCompanion/kotlin.kt b/compiler/testData/codegen/boxWithJava/properties/protectedJavaPropertyInCompanion/kotlin.kt new file mode 100644 index 00000000000..c2bd125c81e --- /dev/null +++ b/compiler/testData/codegen/boxWithJava/properties/protectedJavaPropertyInCompanion/kotlin.kt @@ -0,0 +1,27 @@ +package z + +import JavaBaseClass + +class A { + @JvmField var foo = "fail" + + companion object : JavaBaseClass() { + @JvmStatic fun test(): String { + return runSlowly { + foo = "OK" + foo + } + } + } +} +fun runSlowly(f: () -> String): String { + return f() +} + +fun box(): String { + val a = A() + a.foo = "Kotlin" + if (a.foo != "Kotlin") return "fail" + + return A.test() +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithJavaCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithJavaCodegenTestGenerated.java index 4c2949b6bbd..cf62eb395b7 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithJavaCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithJavaCodegenTestGenerated.java @@ -547,6 +547,18 @@ public class BlackBoxWithJavaCodegenTestGenerated extends AbstractBlackBoxCodege doTestWithJava(fileName); } + @TestMetadata("protectedJavaProperty") + public void testProtectedJavaProperty() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxWithJava/properties/protectedJavaProperty/"); + doTestWithJava(fileName); + } + + @TestMetadata("protectedJavaPropertyInCompanion") + public void testProtectedJavaPropertyInCompanion() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxWithJava/properties/protectedJavaPropertyInCompanion/"); + doTestWithJava(fileName); + } + @TestMetadata("substituteJavaSuperField") public void testSubstituteJavaSuperField() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxWithJava/properties/substituteJavaSuperField/");