From 2df4d9496af6c093a3835fe521da12f95e02aa2b Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Thu, 26 Oct 2017 10:57:37 +0300 Subject: [PATCH] Fix incorrect UNINITIALIZED_ENUM_COMPANION diagnostic #KT-20959 Fixed --- .../kotlin/cfg/PseudocodeVariablesData.kt | 5 +++- .../enum/wrongUnitializedEnumCompanion.kt | 9 +++++++ .../enum/wrongUnitializedEnumCompanion.txt | 27 +++++++++++++++++++ .../checkers/DiagnosticsTestGenerated.java | 6 +++++ .../DiagnosticsUsingJavacTestGenerated.java | 6 +++++ 5 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/diagnostics/tests/enum/wrongUnitializedEnumCompanion.kt create mode 100644 compiler/testData/diagnostics/tests/enum/wrongUnitializedEnumCompanion.txt diff --git a/compiler/frontend/src/org/jetbrains/kotlin/cfg/PseudocodeVariablesData.kt b/compiler/frontend/src/org/jetbrains/kotlin/cfg/PseudocodeVariablesData.kt index 50c804c5f09..9e28b73a1b0 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/cfg/PseudocodeVariablesData.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/cfg/PseudocodeVariablesData.kt @@ -190,7 +190,10 @@ class PseudocodeVariablesData(val pseudocode: Pseudocode, private val bindingCon } private fun WriteValueInstruction.isTrivialInitializer() = - element is KtVariableDeclaration || element is KtParameter + // WriteValueInstruction having KtDeclaration as an element means + // it must be a write happened at the same time when + // the variable (common variable/parameter/object) has been declared + element is KtDeclaration private inner class ReadOnlyInitControlFlowInfoImpl( val declaredSet: ImmutableSet, diff --git a/compiler/testData/diagnostics/tests/enum/wrongUnitializedEnumCompanion.kt b/compiler/testData/diagnostics/tests/enum/wrongUnitializedEnumCompanion.kt new file mode 100644 index 00000000000..256a299c9f7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/wrongUnitializedEnumCompanion.kt @@ -0,0 +1,9 @@ +// See KT-20959 + +enum class Foo {; + companion object { + val x = foo() // there should be no UNINITIALIZED_ENUM_COMPANION + + private fun foo() = "OK" + } +} diff --git a/compiler/testData/diagnostics/tests/enum/wrongUnitializedEnumCompanion.txt b/compiler/testData/diagnostics/tests/enum/wrongUnitializedEnumCompanion.txt new file mode 100644 index 00000000000..526fc64841e --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/wrongUnitializedEnumCompanion.txt @@ -0,0 +1,27 @@ +package + +public final enum class Foo : kotlin.Enum { + private constructor Foo() + public final override /*1*/ /*fake_override*/ val name: kotlin.String + public final override /*1*/ /*fake_override*/ val ordinal: kotlin.Int + protected final override /*1*/ /*fake_override*/ fun clone(): kotlin.Any + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: Foo): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + protected/*protected and package*/ final override /*1*/ /*fake_override*/ /*isHiddenForResolutionEverywhereBesideSupercalls*/ fun finalize(): kotlin.Unit + public final override /*1*/ /*fake_override*/ /*isHiddenForResolutionEverywhereBesideSupercalls*/ fun getDeclaringClass(): java.lang.Class! + 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 x: kotlin.String + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + private final fun foo(): kotlin.String + 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): Foo + public final /*synthesized*/ fun values(): kotlin.Array +} diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 7360f15d678..7c96b8660b1 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -7705,6 +7705,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { doTest(fileName); } + @TestMetadata("wrongUnitializedEnumCompanion.kt") + public void testWrongUnitializedEnumCompanion() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/enum/wrongUnitializedEnumCompanion.kt"); + doTest(fileName); + } + @TestMetadata("compiler/testData/diagnostics/tests/enum/inner") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java index ae4afc91801..dfa8522e249 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java @@ -7705,6 +7705,12 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing doTest(fileName); } + @TestMetadata("wrongUnitializedEnumCompanion.kt") + public void testWrongUnitializedEnumCompanion() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/enum/wrongUnitializedEnumCompanion.kt"); + doTest(fileName); + } + @TestMetadata("compiler/testData/diagnostics/tests/enum/inner") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)