diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java index ef5f57f37fd..4368c1b7702 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java @@ -24782,6 +24782,18 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/jvmField/kt47739.kt"); } + @Test + @TestMetadata("kt48295.kt") + public void testKt48295() throws Exception { + runTest("compiler/testData/codegen/box/jvmField/kt48295.kt"); + } + + @Test + @TestMetadata("kt48295a.kt") + public void testKt48295a() throws Exception { + runTest("compiler/testData/codegen/box/jvmField/kt48295a.kt"); + } + @Test @TestMetadata("publicField.kt") public void testPublicField() throws Exception { diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmPropertiesLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmPropertiesLowering.kt index 85c17934c31..baa41b53558 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmPropertiesLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmPropertiesLowering.kt @@ -116,7 +116,9 @@ class JvmPropertiesLowering(private val backendContext: JvmBackendContext) : IrE val receiver = expression.dispatchReceiver if (receiver != null) { val propertyParent = irProperty.parent - if (propertyParent is IrClass && propertyParent.symbol != receiver.type.classifierOrNull) { + if (propertyParent is IrClass && propertyParent.symbol != receiver.type.classifierOrNull && + expression.superQualifierSymbol == null + ) { return irImplicitCast(receiver, propertyParent.defaultType) } } diff --git a/compiler/testData/codegen/box/jvmField/kt48295.kt b/compiler/testData/codegen/box/jvmField/kt48295.kt new file mode 100644 index 00000000000..77cff1c08bc --- /dev/null +++ b/compiler/testData/codegen/box/jvmField/kt48295.kt @@ -0,0 +1,21 @@ +// TARGET_BACKEND: JVM +// WITH_RUNTIME + +// FILE: a.kt + +package a + +open class A { + @JvmField protected var result = "Fail" +} + +// FILE: b.kt + +class B : a.A() { + fun test(): String { + super.result = "OK" + return super.result + } +} + +fun box(): String = B().test() diff --git a/compiler/testData/codegen/box/jvmField/kt48295a.kt b/compiler/testData/codegen/box/jvmField/kt48295a.kt new file mode 100644 index 00000000000..69900f7551d --- /dev/null +++ b/compiler/testData/codegen/box/jvmField/kt48295a.kt @@ -0,0 +1,23 @@ +// TARGET_BACKEND: JVM +// WITH_RUNTIME + +// FILE: a.kt + +package a + +open class A { + @JvmField protected var result = "Fail" +} + +open class AA : A() + +// FILE: b.kt + +class B : a.AA() { + fun test(): String { + super.result = "OK" + return super.result + } +} + +fun box(): String = B().test() diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java index 30d979fd0c3..9cfae406a24 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java @@ -24632,6 +24632,18 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/jvmField/kt47739.kt"); } + @Test + @TestMetadata("kt48295.kt") + public void testKt48295() throws Exception { + runTest("compiler/testData/codegen/box/jvmField/kt48295.kt"); + } + + @Test + @TestMetadata("kt48295a.kt") + public void testKt48295a() throws Exception { + runTest("compiler/testData/codegen/box/jvmField/kt48295a.kt"); + } + @Test @TestMetadata("publicField.kt") public void testPublicField() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java index 61f32e9e0a2..f84b547ea3a 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java @@ -24782,6 +24782,18 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/jvmField/kt47739.kt"); } + @Test + @TestMetadata("kt48295.kt") + public void testKt48295() throws Exception { + runTest("compiler/testData/codegen/box/jvmField/kt48295.kt"); + } + + @Test + @TestMetadata("kt48295a.kt") + public void testKt48295a() throws Exception { + runTest("compiler/testData/codegen/box/jvmField/kt48295a.kt"); + } + @Test @TestMetadata("publicField.kt") public void testPublicField() throws Exception { diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 7dc64c0a13b..5985432e290 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -20763,6 +20763,16 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/jvmField/kt47739.kt"); } + @TestMetadata("kt48295.kt") + public void testKt48295() throws Exception { + runTest("compiler/testData/codegen/box/jvmField/kt48295.kt"); + } + + @TestMetadata("kt48295a.kt") + public void testKt48295a() throws Exception { + runTest("compiler/testData/codegen/box/jvmField/kt48295a.kt"); + } + @TestMetadata("publicField.kt") public void testPublicField() throws Exception { runTest("compiler/testData/codegen/box/jvmField/publicField.kt");