diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/AccessorForPropertyDescriptor.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/AccessorForPropertyDescriptor.java index c9618dc2b82..b0b216e160f 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/AccessorForPropertyDescriptor.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/AccessorForPropertyDescriptor.java @@ -46,7 +46,9 @@ public class AccessorForPropertyDescriptor extends PropertyDescriptorImpl implem boolean setterAccessorRequired ) { this(property, property.getType(), DescriptorUtils.getReceiverParameterType(property.getExtensionReceiverParameter()), - property.getDispatchReceiverParameter(), containingDeclaration, superCallTarget, nameSuffix, + /* dispatchReceiverParameter = */ + CodegenUtilKt.isJvmStaticInObjectOrClass(property) ? null : property.getDispatchReceiverParameter(), + containingDeclaration, superCallTarget, nameSuffix, getterAccessorRequired, setterAccessorRequired); } @@ -62,7 +64,7 @@ public class AccessorForPropertyDescriptor extends PropertyDescriptorImpl implem this(original, propertyType, receiverType, dispatchReceiverParameter, containingDeclaration, superCallTarget, nameSuffix, true, true); } - protected AccessorForPropertyDescriptor( + private AccessorForPropertyDescriptor( @NotNull PropertyDescriptor original, @NotNull KotlinType propertyType, @Nullable KotlinType receiverType, diff --git a/compiler/testData/codegen/box/jvmStatic/inlinePropertyAccessors.kt b/compiler/testData/codegen/box/jvmStatic/inlinePropertyAccessors.kt new file mode 100644 index 00000000000..fdcadc64935 --- /dev/null +++ b/compiler/testData/codegen/box/jvmStatic/inlinePropertyAccessors.kt @@ -0,0 +1,15 @@ +// WITH_RUNTIME + +var result = "fail 1" +object Foo { + @JvmStatic + private val a = "OK" + + fun foo() = run { result = a } +} + +fun box(): String { + Foo.foo() + + return result +} diff --git a/compiler/testData/codegen/box/jvmStatic/propertyAccessorsCompanion.kt b/compiler/testData/codegen/box/jvmStatic/propertyAccessorsCompanion.kt new file mode 100644 index 00000000000..998b3132501 --- /dev/null +++ b/compiler/testData/codegen/box/jvmStatic/propertyAccessorsCompanion.kt @@ -0,0 +1,20 @@ +// WITH_RUNTIME + +var result = "fail 2" +class Foo { + val b = { a } + val c = Runnable { result = a } + + companion object { + @JvmStatic + private val a = "OK" + } +} + +fun box(): String { + if (Foo().b() != "OK") return "fail 1" + + Foo().c.run() + + return result +} diff --git a/compiler/testData/codegen/box/jvmStatic/propertyAccessorsObject.kt b/compiler/testData/codegen/box/jvmStatic/propertyAccessorsObject.kt new file mode 100644 index 00000000000..dfd01398287 --- /dev/null +++ b/compiler/testData/codegen/box/jvmStatic/propertyAccessorsObject.kt @@ -0,0 +1,18 @@ +// WITH_RUNTIME + +var result = "fail 2" +object Foo { + @JvmStatic + private val a = "OK" + + val b = { a } + val c = Runnable { result = a } +} + +fun box(): String { + if (Foo.b() != "OK") return "fail 1" + + Foo.c.run() + + return result +} diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 86997128f39..be8627c7cd0 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -8485,6 +8485,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } + @TestMetadata("inlinePropertyAccessors.kt") + public void testInlinePropertyAccessors() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/jvmStatic/inlinePropertyAccessors.kt"); + doTest(fileName); + } + @TestMetadata("kt9897_static.kt") public void testKt9897_static() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/jvmStatic/kt9897_static.kt"); @@ -8527,6 +8533,18 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } + @TestMetadata("propertyAccessorsCompanion.kt") + public void testPropertyAccessorsCompanion() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/jvmStatic/propertyAccessorsCompanion.kt"); + doTest(fileName); + } + + @TestMetadata("propertyAccessorsObject.kt") + public void testPropertyAccessorsObject() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/jvmStatic/propertyAccessorsObject.kt"); + doTest(fileName); + } + @TestMetadata("propertyAsDefault.kt") public void testPropertyAsDefault() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/jvmStatic/propertyAsDefault.kt");