Files
kotlin/compiler/testData/codegen/box/enum/enumEntryReferenceFromInnerClassConstructor3.kt
Dmitry Petrov 7c3d079eeb 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.

(cherry picked from commit 41b1594)
2017-10-26 16:10:51 +03:00

23 lines
413 B
Kotlin
Vendored

interface IFoo {
fun foo(): String
}
interface IBar {
fun bar(): String
}
enum class Test : IFoo, IBar {
FOO {
// FOO referenced from inner class constructor with initialized 'this',
// in delegate initializer
inner class Inner : IFoo by FOO
val z = Inner()
override fun foo() = "OK"
override fun bar() = z.foo()
}
}
fun box() = Test.FOO.bar()