Fix issues with enum entry self-reference

Given a singleton class 'S' with possibly uninitialized static instance
(enum entry, interface companion object).
Such singleton can be referenced by name, or as an explicit or implicit
'this'.
For a given singleton class 'S' we
either use 'this@S' from context (local or captured),
or 'S' as a static instance.

Local or captured 'this@S' should be used if:
  - we are in the constructor for 'S',
    and corresponding instance is initialized
        by super or delegating constructor call;
  - we are in any other member of 'S' or any of its inner classes.

Otherwise, a static instance should be used.
This commit is contained in:
Dmitry Petrov
2017-10-26 11:43:31 +03:00
parent dd9f12d2e5
commit 28535a57d8
10 changed files with 247 additions and 6 deletions
@@ -7934,6 +7934,24 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
doTest(fileName);
}
@TestMetadata("enumEntryReferenceFromInnerClassConstructor1.kt")
public void testEnumEntryReferenceFromInnerClassConstructor1() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/enum/enumEntryReferenceFromInnerClassConstructor1.kt");
doTest(fileName);
}
@TestMetadata("enumEntryReferenceFromInnerClassConstructor2.kt")
public void testEnumEntryReferenceFromInnerClassConstructor2() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/enum/enumEntryReferenceFromInnerClassConstructor2.kt");
doTest(fileName);
}
@TestMetadata("enumEntryReferenceFromInnerClassConstructor3.kt")
public void testEnumEntryReferenceFromInnerClassConstructor3() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/enum/enumEntryReferenceFromInnerClassConstructor3.kt");
doTest(fileName);
}
@TestMetadata("enumInheritedFromTrait.kt")
public void testEnumInheritedFromTrait() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/enum/enumInheritedFromTrait.kt");
@@ -8012,6 +8030,18 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
doTest(fileName);
}
@TestMetadata("kt20651a.kt")
public void testKt20651a() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/enum/kt20651a.kt");
doTest(fileName);
}
@TestMetadata("kt20651b.kt")
public void testKt20651b() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/enum/kt20651b.kt");
doTest(fileName);
}
@TestMetadata("kt2350.kt")
public void testKt2350() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/enum/kt2350.kt");