IrInterpreter: interpret IrGetField properly
This commit is contained in:
+6
@@ -13700,6 +13700,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/fir"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("ConstValAccess.kt")
|
||||
public void testConstValAccess() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/fir/ConstValAccess.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("ExtensionAlias.kt")
|
||||
public void testExtensionAlias() throws Exception {
|
||||
|
||||
+7
@@ -168,6 +168,13 @@ class IrCompileTimeChecker(
|
||||
|
||||
override fun visitGetField(expression: IrGetField, data: Nothing?): Boolean {
|
||||
val owner = expression.symbol.owner
|
||||
if (owner.origin == IrDeclarationOrigin.PROPERTY_BACKING_FIELD && owner.correspondingPropertySymbol?.owner?.isConst == true) {
|
||||
val receiverComputable = expression.receiver?.accept(this, null) ?: true
|
||||
val initializerComputable = owner.initializer?.accept(this, null) ?: false
|
||||
if (receiverComputable && initializerComputable) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
val parent = owner.parent as IrSymbolOwner
|
||||
val isJavaPrimitiveStatic = owner.origin == IrDeclarationOrigin.IR_EXTERNAL_JAVA_DECLARATION_STUB && owner.isStatic &&
|
||||
(owner.type.isPrimitiveType() || owner.type.isStringClassType())
|
||||
|
||||
@@ -540,6 +540,9 @@ class IrInterpreter(private val irBuiltIns: IrBuiltIns, private val bodyMap: Map
|
||||
stack.pushReturnValue(Wrapper.getStaticGetter(field)!!.invokeWithArguments().toState(field.type))
|
||||
return Next
|
||||
}
|
||||
if (field.origin == IrDeclarationOrigin.PROPERTY_BACKING_FIELD && field.correspondingPropertySymbol?.owner?.isConst == true) {
|
||||
return field.initializer?.expression?.interpret() ?: Next
|
||||
}
|
||||
// receiver is null, for example, for top level fields
|
||||
val result = receiver?.let { stack.getVariable(receiver).state.getState(field.correspondingPropertySymbol!!) }
|
||||
?: return (expression.symbol.owner.initializer?.expression?.interpret() ?: Next)
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
// MODULE: lib
|
||||
// FILE: A.kt
|
||||
|
||||
object Obj {
|
||||
const val A_CONST = "O"
|
||||
}
|
||||
|
||||
// MODULE: main(lib)
|
||||
// FILE: B.kt
|
||||
|
||||
fun box(): String {
|
||||
val s = B_CONST
|
||||
return s + "K";
|
||||
}
|
||||
|
||||
const val B_CONST = Obj.A_CONST
|
||||
+6
@@ -13700,6 +13700,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/fir"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("ConstValAccess.kt")
|
||||
public void testConstValAccess() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/fir/ConstValAccess.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("ExtensionAlias.kt")
|
||||
public void testExtensionAlias() throws Exception {
|
||||
|
||||
+6
@@ -13700,6 +13700,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/fir"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("ConstValAccess.kt")
|
||||
public void testConstValAccess() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/fir/ConstValAccess.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("ExtensionAlias.kt")
|
||||
public void testExtensionAlias() throws Exception {
|
||||
|
||||
+5
@@ -12042,6 +12042,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/fir"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
|
||||
}
|
||||
|
||||
@TestMetadata("ConstValAccess.kt")
|
||||
public void testConstValAccess() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/fir/ConstValAccess.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ExtensionAlias.kt")
|
||||
public void testExtensionAlias() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/fir/ExtensionAlias.kt");
|
||||
|
||||
Reference in New Issue
Block a user