[JVM IR] Fix issue where fields are not being set to their default

values within initializer blocks.

The issue occurs in code like this:
```
class C {
  var b = true
  init {
    b = false   // Missing PUTFIELD for this statement
  }
}
```

Added a new statement origin for field initialization (at declaration)
instead of relying on `origin == null` in ExpressionCodegen to determine
whether to generate the initializations.

This was unintentionally broken in
d68a1898d0.
This commit is contained in:
Mark Punzalan
2020-02-14 13:19:59 -08:00
committed by Dmitry Petrov
parent 56c819f06e
commit 64141b8b38
17 changed files with 464 additions and 8 deletions
@@ -2758,6 +2758,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/classes/initializerBlockDImpl.kt");
}
@TestMetadata("initializerBlockResetToDefault.kt")
public void testInitializerBlockResetToDefault() throws Exception {
runTest("compiler/testData/codegen/box/classes/initializerBlockResetToDefault.kt");
}
@TestMetadata("innerClass.kt")
public void testInnerClass() throws Exception {
runTest("compiler/testData/codegen/box/classes/innerClass.kt");
@@ -13324,6 +13329,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/objects/initializationOrder.kt");
}
@TestMetadata("initializerBlockResetToDefault.kt")
public void testInitializerBlockResetToDefault() throws Exception {
runTest("compiler/testData/codegen/box/objects/initializerBlockResetToDefault.kt");
}
@TestMetadata("interfaceCompanion.kt")
public void testInterfaceCompanion() throws Exception {
runTest("compiler/testData/codegen/box/objects/interfaceCompanion.kt");
@@ -2758,6 +2758,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/classes/initializerBlockDImpl.kt");
}
@TestMetadata("initializerBlockResetToDefault.kt")
public void testInitializerBlockResetToDefault() throws Exception {
runTest("compiler/testData/codegen/box/classes/initializerBlockResetToDefault.kt");
}
@TestMetadata("innerClass.kt")
public void testInnerClass() throws Exception {
runTest("compiler/testData/codegen/box/classes/innerClass.kt");
@@ -13389,6 +13394,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/objects/initializationOrder.kt");
}
@TestMetadata("initializerBlockResetToDefault.kt")
public void testInitializerBlockResetToDefault() throws Exception {
runTest("compiler/testData/codegen/box/objects/initializerBlockResetToDefault.kt");
}
@TestMetadata("interfaceCompanion.kt")
public void testInterfaceCompanion() throws Exception {
runTest("compiler/testData/codegen/box/objects/interfaceCompanion.kt");