JVM_IR: fix const reads from other files in same module

This commit is contained in:
pyos
2019-10-01 10:11:41 +02:00
committed by Alexander Udalov
parent eda4206428
commit 6e9ee2a46c
5 changed files with 23 additions and 2 deletions
@@ -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)
}
@@ -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
@@ -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");
@@ -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");
@@ -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");