diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/ConstLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/ConstLowering.kt index 0f83133b443..1e3a48b3654 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/ConstLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/ConstLowering.kt @@ -49,8 +49,7 @@ class ConstLowering(val context: JvmBackendContext) : IrElementTransformerVoid() override fun visitCall(expression: IrCall): IrExpression { val function = (expression.symbol.owner as? IrSimpleFunction) ?: return super.visitCall(expression) val property = function.correspondingPropertySymbol?.owner ?: return super.visitCall(expression) - if (function != property.getter) - return super.visitCall(expression) + // If `constantValue` is not null, `function` can only be the getter because the property is immutable. return expression.lowerConstRead(property.backingField) ?: super.visitCall(expression) } diff --git a/compiler/testData/codegen/box/properties/const/anotherFile.kt b/compiler/testData/codegen/box/properties/const/anotherFile.kt new file mode 100644 index 00000000000..a46dfa72191 --- /dev/null +++ b/compiler/testData/codegen/box/properties/const/anotherFile.kt @@ -0,0 +1,7 @@ +// FILE: 1.kt +// File names are important! This file should come before the other one +// in a lexicographic order. +const val x = "OK" + +// FILE: 2.kt +fun box() = x diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 0de0fadcfd8..df9cc7c6583 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -18626,6 +18626,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/properties/const"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); } + @TestMetadata("anotherFile.kt") + public void testAnotherFile() throws Exception { + runTest("compiler/testData/codegen/box/properties/const/anotherFile.kt"); + } + @TestMetadata("constFlags.kt") public void testConstFlags() throws Exception { runTest("compiler/testData/codegen/box/properties/const/constFlags.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 52fcf316ee9..31427e2310e 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -18626,6 +18626,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/properties/const"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); } + @TestMetadata("anotherFile.kt") + public void testAnotherFile() throws Exception { + runTest("compiler/testData/codegen/box/properties/const/anotherFile.kt"); + } + @TestMetadata("constFlags.kt") public void testConstFlags() throws Exception { runTest("compiler/testData/codegen/box/properties/const/constFlags.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 6325b35b6e4..e4b2c946ab9 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -17511,6 +17511,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/properties/const"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM_IR, true); } + @TestMetadata("anotherFile.kt") + public void testAnotherFile() throws Exception { + runTest("compiler/testData/codegen/box/properties/const/anotherFile.kt"); + } + @TestMetadata("constFlags.kt") public void testConstFlags() throws Exception { runTest("compiler/testData/codegen/box/properties/const/constFlags.kt");