JVM_IR: fix const reads from other files in same module
This commit is contained in:
@@ -49,8 +49,7 @@ class ConstLowering(val context: JvmBackendContext) : IrElementTransformerVoid()
|
|||||||
override fun visitCall(expression: IrCall): IrExpression {
|
override fun visitCall(expression: IrCall): IrExpression {
|
||||||
val function = (expression.symbol.owner as? IrSimpleFunction) ?: return super.visitCall(expression)
|
val function = (expression.symbol.owner as? IrSimpleFunction) ?: return super.visitCall(expression)
|
||||||
val property = function.correspondingPropertySymbol?.owner ?: return super.visitCall(expression)
|
val property = function.correspondingPropertySymbol?.owner ?: return super.visitCall(expression)
|
||||||
if (function != property.getter)
|
// If `constantValue` is not null, `function` can only be the getter because the property is immutable.
|
||||||
return super.visitCall(expression)
|
|
||||||
return expression.lowerConstRead(property.backingField) ?: super.visitCall(expression)
|
return expression.lowerConstRead(property.backingField) ?: super.visitCall(expression)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
+5
@@ -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);
|
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")
|
@TestMetadata("constFlags.kt")
|
||||||
public void testConstFlags() throws Exception {
|
public void testConstFlags() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/properties/const/constFlags.kt");
|
runTest("compiler/testData/codegen/box/properties/const/constFlags.kt");
|
||||||
|
|||||||
+5
@@ -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);
|
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")
|
@TestMetadata("constFlags.kt")
|
||||||
public void testConstFlags() throws Exception {
|
public void testConstFlags() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/properties/const/constFlags.kt");
|
runTest("compiler/testData/codegen/box/properties/const/constFlags.kt");
|
||||||
|
|||||||
+5
@@ -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);
|
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")
|
@TestMetadata("constFlags.kt")
|
||||||
public void testConstFlags() throws Exception {
|
public void testConstFlags() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/properties/const/constFlags.kt");
|
runTest("compiler/testData/codegen/box/properties/const/constFlags.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user