KT-52551 Create a static initialization section in case of delegation to a property reference from a file class

This commit is contained in:
Pavel Mikhailovskii
2022-05-27 19:41:59 +02:00
committed by teamcity
parent 0b9e5e14be
commit 2ceccec2b8
10 changed files with 64 additions and 1 deletions
@@ -14583,6 +14583,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
public void testWithSideEffects() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/delegateToAnother/withSideEffects.kt");
}
@Test
@TestMetadata("withSideEffectsFromFileClass.kt")
public void testWithSideEffectsFromFileClass() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/delegateToAnother/withSideEffectsFromFileClass.kt");
}
}
@Nested
@@ -172,7 +172,13 @@ private class PropertyReferenceDelegationTransformer(val context: JvmBackendCont
// When the receiver is inlined, it can have side effects in form of class initialization, so it should be evaluated here.
val receiverBlock = receiver.takeIf { backingField == null }?.let {
val symbol = IrAnonymousInitializerSymbolImpl(parentAsClass.symbol)
context.irFactory.createAnonymousInitializer(it.startOffset, it.endOffset, IrDeclarationOrigin.DEFINED, symbol).apply {
context.irFactory.createAnonymousInitializer(
it.startOffset,
it.endOffset,
IrDeclarationOrigin.DEFINED,
symbol,
parentAsClass.isFacadeClass
).apply {
body = context.irFactory.createBlockBody(startOffset, endOffset, listOf(it.inline(null, null)))
}
}
@@ -0,0 +1,11 @@
// WITH_STDLIB
var initialized = false
object O {
val z = "OK"
init { initialized = true }
}
val x by O::z
fun box(): String = if (initialized) x else "Fail"
@@ -14463,6 +14463,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
public void testWithSideEffects() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/delegateToAnother/withSideEffects.kt");
}
@Test
@TestMetadata("withSideEffectsFromFileClass.kt")
public void testWithSideEffectsFromFileClass() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/delegateToAnother/withSideEffectsFromFileClass.kt");
}
}
@Nested
@@ -14583,6 +14583,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
public void testWithSideEffects() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/delegateToAnother/withSideEffects.kt");
}
@Test
@TestMetadata("withSideEffectsFromFileClass.kt")
public void testWithSideEffectsFromFileClass() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/delegateToAnother/withSideEffectsFromFileClass.kt");
}
}
@Nested
@@ -11797,6 +11797,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
public void testWithSideEffects() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/delegateToAnother/withSideEffects.kt");
}
@TestMetadata("withSideEffectsFromFileClass.kt")
public void testWithSideEffectsFromFileClass() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/delegateToAnother/withSideEffectsFromFileClass.kt");
}
}
@TestMetadata("compiler/testData/codegen/box/delegatedProperty/local")
@@ -11027,6 +11027,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
public void testWithSideEffects() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/delegateToAnother/withSideEffects.kt");
}
@Test
@TestMetadata("withSideEffectsFromFileClass.kt")
public void testWithSideEffectsFromFileClass() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/delegateToAnother/withSideEffectsFromFileClass.kt");
}
}
@Nested
@@ -11069,6 +11069,12 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
public void testWithSideEffects() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/delegateToAnother/withSideEffects.kt");
}
@Test
@TestMetadata("withSideEffectsFromFileClass.kt")
public void testWithSideEffectsFromFileClass() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/delegateToAnother/withSideEffectsFromFileClass.kt");
}
}
@Nested
@@ -9792,6 +9792,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
public void testWithSideEffects() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/delegateToAnother/withSideEffects.kt");
}
@TestMetadata("withSideEffectsFromFileClass.kt")
public void testWithSideEffectsFromFileClass() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/delegateToAnother/withSideEffectsFromFileClass.kt");
}
}
@TestMetadata("compiler/testData/codegen/box/delegatedProperty/local")
@@ -12029,6 +12029,12 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest
public void testWithSideEffects() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/delegateToAnother/withSideEffects.kt");
}
@Test
@TestMetadata("withSideEffectsFromFileClass.kt")
public void testWithSideEffectsFromFileClass() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/delegateToAnother/withSideEffectsFromFileClass.kt");
}
}
@Nested