diff --git a/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowProcessor.kt b/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowProcessor.kt index 091a3eb6b85..10cdcb3570b 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowProcessor.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowProcessor.kt @@ -1267,6 +1267,16 @@ class ControlFlowProcessor(private val trace: BindingTrace) { } override fun visitClass(klass: KtClass) { + if (klass.hasPrimaryConstructor()) { + processParameters(klass.getPrimaryConstructorParameters()) + + // delegation specifiers of primary constructor, anonymous class and property initializers + generateHeaderDelegationSpecifiers(klass) + generateInitializersForScriptClassOrObject(klass) + } + + generateDeclarationForLocalClassOrObjectIfNeeded(klass) + if (klass.isEnum()) { klass.declarations.forEach { when (it) { @@ -1279,21 +1289,12 @@ class ControlFlowProcessor(private val trace: BindingTrace) { generateInstructions(it) } } - is KtObjectDeclaration -> { + is KtObjectDeclaration -> if (it.isCompanion()) { generateInstructions(it) } } } } - if (klass.hasPrimaryConstructor()) { - processParameters(klass.getPrimaryConstructorParameters()) - - // delegation specifiers of primary constructor, anonymous class and property initializers - generateHeaderDelegationSpecifiers(klass) - generateInitializersForScriptClassOrObject(klass) - } - - generateDeclarationForLocalClassOrObjectIfNeeded(klass) } override fun visitScript(script: KtScript) { diff --git a/compiler/testData/cfg/declarations/classesAndObjects/ObjectEnumQualifiers.instructions b/compiler/testData/cfg/declarations/classesAndObjects/ObjectEnumQualifiers.instructions index 1113535e1cb..474d51a914e 100644 --- a/compiler/testData/cfg/declarations/classesAndObjects/ObjectEnumQualifiers.instructions +++ b/compiler/testData/cfg/declarations/classesAndObjects/ObjectEnumQualifiers.instructions @@ -22,15 +22,15 @@ enum class E(val x: Int) { --------------------- L0: 1 - v(E1(0)) - magic[FAKE_INITIALIZER](E1(0)) -> - w(E1|) - r(0) -> - mark((0)) - call((0), |) -> v(val x: Int) - magic[FAKE_INITIALIZER](val x: Int) -> - w(x|) + magic[FAKE_INITIALIZER](val x: Int) -> + w(x|) + v(E1(0)) + magic[FAKE_INITIALIZER](E1(0)) -> + w(E1|) + r(0) -> + mark((0)) + call((0), |) -> L1: NEXT:[] error: diff --git a/compiler/testData/cfg/declarations/classesAndObjects/ObjectEnumQualifiers.values b/compiler/testData/cfg/declarations/classesAndObjects/ObjectEnumQualifiers.values index c0d97248c62..5add0958141 100644 --- a/compiler/testData/cfg/declarations/classesAndObjects/ObjectEnumQualifiers.values +++ b/compiler/testData/cfg/declarations/classesAndObjects/ObjectEnumQualifiers.values @@ -10,10 +10,10 @@ enum class E(val x: Int) { E1(0) } --------------------- - : E NEW: magic[FAKE_INITIALIZER](E1(0)) -> - : Int NEW: magic[FAKE_INITIALIZER](val x: Int) -> -0 : Int NEW: r(0) -> -(0) : * NEW: call((0), |) -> + : Int NEW: magic[FAKE_INITIALIZER](val x: Int) -> + : E NEW: magic[FAKE_INITIALIZER](E1(0)) -> +0 : Int NEW: r(0) -> +(0) : * NEW: call((0), |) -> ===================== == C == class C { diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/enumInterdependence.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/enumInterdependence.kt index 402b298ae9c..2d20f10c746 100644 --- a/compiler/testData/diagnostics/tests/controlFlowAnalysis/enumInterdependence.kt +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/enumInterdependence.kt @@ -29,7 +29,8 @@ enum class D(val x: Int) { } enum class E(val v: Int) { - E1(Nested.COPY); + // KT-11769 related: there is no predictable initialization order for enum entry with non-companion object + E1(Nested.COPY); object Nested { val COPY = E1.v @@ -41,4 +42,25 @@ object Object1 { object Object2 { val z: Any = Object1.y } -} \ No newline at end of file +} + +// From KT-11769 +enum class Fruit(personal: Int) { + APPLE(1); + + companion object { + val common = 20 + } + + val score = personal + common +} + +// From KT-6054 +enum class MyEnum { + A, B; + val x = when(this) { + A -> 1 + B -> 2 + else -> 3 + } +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/enumInterdependence.txt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/enumInterdependence.txt index a52dc71db6d..68b14a48ec8 100644 --- a/compiler/testData/diagnostics/tests/controlFlowAnalysis/enumInterdependence.txt +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/enumInterdependence.txt @@ -134,6 +134,52 @@ public final enum class E : kotlin.Enum { public final /*synthesized*/ fun values(): kotlin.Array } +public final enum class Fruit : kotlin.Enum { + enum entry APPLE + + private constructor Fruit(/*0*/ personal: kotlin.Int) + public final override /*1*/ /*fake_override*/ val name: kotlin.String + public final override /*1*/ /*fake_override*/ val ordinal: kotlin.Int + public final val score: kotlin.Int + protected final override /*1*/ /*fake_override*/ fun clone(): kotlin.Any + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: Fruit): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + public companion object Companion { + private constructor Companion() + public final val common: kotlin.Int = 20 + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + // Static members + public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): Fruit + public final /*synthesized*/ fun values(): kotlin.Array +} + +public final enum class MyEnum : kotlin.Enum { + enum entry A + + enum entry B + + private constructor MyEnum() + public final override /*1*/ /*fake_override*/ val name: kotlin.String + public final override /*1*/ /*fake_override*/ val ordinal: kotlin.Int + public final val x: kotlin.Int + protected final override /*1*/ /*fake_override*/ fun clone(): kotlin.Any + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: MyEnum): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + // Static members + public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): MyEnum + public final /*synthesized*/ fun values(): kotlin.Array +} + public object Object1 { private constructor Object1() public final val y: kotlin.Any