Initialize class companion object fields on accessing its java class
This commit is contained in:
@@ -1001,6 +1001,12 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
InstructionAdapter v = createOrGetClInitCodegen().v;
|
InstructionAdapter v = createOrGetClInitCodegen().v;
|
||||||
v.anew(classAsmType);
|
v.anew(classAsmType);
|
||||||
v.invokespecial(classAsmType.getInternalName(), "<init>", "()V", false);
|
v.invokespecial(classAsmType.getInternalName(), "<init>", "()V", false);
|
||||||
|
if (isCompanionObjectWithBackingFieldsInOuter(descriptor)) {
|
||||||
|
//We should load containing class to initialize companion fields
|
||||||
|
StackValue companion = StackValue.singletonForCompanion(descriptor, typeMapper);
|
||||||
|
companion.put(companion.type, v);
|
||||||
|
AsmUtil.pop(v, companion.type);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
var result = "OK"
|
||||||
|
|
||||||
|
class A {
|
||||||
|
companion object {
|
||||||
|
var z = result
|
||||||
|
|
||||||
|
fun patchResult() {
|
||||||
|
result = "fail"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
A.patchResult()
|
||||||
|
return A.z
|
||||||
|
}
|
||||||
+6
@@ -5560,6 +5560,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("initializationOrder.kt")
|
||||||
|
public void testInitializationOrder() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/objects/initializationOrder.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt1047.kt")
|
@TestMetadata("kt1047.kt")
|
||||||
public void testKt1047() throws Exception {
|
public void testKt1047() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/objects/kt1047.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/objects/kt1047.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user