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
+8
View File
@@ -0,0 +1,8 @@
enum class Foo(
val x: String,
val callback: () -> String
) {
FOO("OK", { FOO.x })
}
fun box() = Foo.FOO.callback()