diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java index 714c84c2e07..4d65d18f14b 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java @@ -10391,18 +10391,36 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag runTest("compiler/testData/diagnostics/tests/enum/entries/entriesPropertyAsExtensionClash.kt"); } + @Test + @TestMetadata("entriesPropertyAsExtensionClashOn.kt") + public void testEntriesPropertyAsExtensionClashOn() throws Exception { + runTest("compiler/testData/diagnostics/tests/enum/entries/entriesPropertyAsExtensionClashOn.kt"); + } + @Test @TestMetadata("entriesPropertyImportedClash.kt") public void testEntriesPropertyImportedClash() throws Exception { runTest("compiler/testData/diagnostics/tests/enum/entries/entriesPropertyImportedClash.kt"); } + @Test + @TestMetadata("entriesPropertyImportedClashOn.kt") + public void testEntriesPropertyImportedClashOn() throws Exception { + runTest("compiler/testData/diagnostics/tests/enum/entries/entriesPropertyImportedClashOn.kt"); + } + @Test @TestMetadata("entriesPropertyInCompanionClash.kt") public void testEntriesPropertyInCompanionClash() throws Exception { runTest("compiler/testData/diagnostics/tests/enum/entries/entriesPropertyInCompanionClash.kt"); } + @Test + @TestMetadata("entriesPropertyInCompanionClashOn.kt") + public void testEntriesPropertyInCompanionClashOn() throws Exception { + runTest("compiler/testData/diagnostics/tests/enum/entries/entriesPropertyInCompanionClashOn.kt"); + } + @Test @TestMetadata("entriesPropertyWithJvmStaticClash.kt") public void testEntriesPropertyWithJvmStaticClash() throws Exception { @@ -10439,11 +10457,23 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag runTest("compiler/testData/diagnostics/tests/enum/entries/nameShadowingOfExternallyDefinedEntries.kt"); } + @Test + @TestMetadata("nameShadowingOfExternallyDefinedEntriesOn.kt") + public void testNameShadowingOfExternallyDefinedEntriesOn() throws Exception { + runTest("compiler/testData/diagnostics/tests/enum/entries/nameShadowingOfExternallyDefinedEntriesOn.kt"); + } + @Test @TestMetadata("redeclarationOfEnumEntriesNameWithIntrinsic.kt") public void testRedeclarationOfEnumEntriesNameWithIntrinsic() throws Exception { runTest("compiler/testData/diagnostics/tests/enum/entries/redeclarationOfEnumEntriesNameWithIntrinsic.kt"); } + + @Test + @TestMetadata("redeclarationOfEnumEntriesNameWithIntrinsicOn.kt") + public void testRedeclarationOfEnumEntriesNameWithIntrinsicOn() throws Exception { + runTest("compiler/testData/diagnostics/tests/enum/entries/redeclarationOfEnumEntriesNameWithIntrinsicOn.kt"); + } } @Nested diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java index 00580c4f84c..b2763983d3f 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java @@ -10397,18 +10397,36 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/enum/entries/entriesPropertyAsExtensionClash.kt"); } + @Test + @TestMetadata("entriesPropertyAsExtensionClashOn.kt") + public void testEntriesPropertyAsExtensionClashOn() throws Exception { + runTest("compiler/testData/diagnostics/tests/enum/entries/entriesPropertyAsExtensionClashOn.kt"); + } + @Test @TestMetadata("entriesPropertyImportedClash.kt") public void testEntriesPropertyImportedClash() throws Exception { runTest("compiler/testData/diagnostics/tests/enum/entries/entriesPropertyImportedClash.kt"); } + @Test + @TestMetadata("entriesPropertyImportedClashOn.kt") + public void testEntriesPropertyImportedClashOn() throws Exception { + runTest("compiler/testData/diagnostics/tests/enum/entries/entriesPropertyImportedClashOn.kt"); + } + @Test @TestMetadata("entriesPropertyInCompanionClash.kt") public void testEntriesPropertyInCompanionClash() throws Exception { runTest("compiler/testData/diagnostics/tests/enum/entries/entriesPropertyInCompanionClash.kt"); } + @Test + @TestMetadata("entriesPropertyInCompanionClashOn.kt") + public void testEntriesPropertyInCompanionClashOn() throws Exception { + runTest("compiler/testData/diagnostics/tests/enum/entries/entriesPropertyInCompanionClashOn.kt"); + } + @Test @TestMetadata("entriesPropertyWithJvmStaticClash.kt") public void testEntriesPropertyWithJvmStaticClash() throws Exception { @@ -10445,11 +10463,23 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/enum/entries/nameShadowingOfExternallyDefinedEntries.kt"); } + @Test + @TestMetadata("nameShadowingOfExternallyDefinedEntriesOn.kt") + public void testNameShadowingOfExternallyDefinedEntriesOn() throws Exception { + runTest("compiler/testData/diagnostics/tests/enum/entries/nameShadowingOfExternallyDefinedEntriesOn.kt"); + } + @Test @TestMetadata("redeclarationOfEnumEntriesNameWithIntrinsic.kt") public void testRedeclarationOfEnumEntriesNameWithIntrinsic() throws Exception { runTest("compiler/testData/diagnostics/tests/enum/entries/redeclarationOfEnumEntriesNameWithIntrinsic.kt"); } + + @Test + @TestMetadata("redeclarationOfEnumEntriesNameWithIntrinsicOn.kt") + public void testRedeclarationOfEnumEntriesNameWithIntrinsicOn() throws Exception { + runTest("compiler/testData/diagnostics/tests/enum/entries/redeclarationOfEnumEntriesNameWithIntrinsicOn.kt"); + } } @Nested diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java index 80c0cde476c..2cc3b8c93f4 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java @@ -10391,18 +10391,36 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac runTest("compiler/testData/diagnostics/tests/enum/entries/entriesPropertyAsExtensionClash.kt"); } + @Test + @TestMetadata("entriesPropertyAsExtensionClashOn.kt") + public void testEntriesPropertyAsExtensionClashOn() throws Exception { + runTest("compiler/testData/diagnostics/tests/enum/entries/entriesPropertyAsExtensionClashOn.kt"); + } + @Test @TestMetadata("entriesPropertyImportedClash.kt") public void testEntriesPropertyImportedClash() throws Exception { runTest("compiler/testData/diagnostics/tests/enum/entries/entriesPropertyImportedClash.kt"); } + @Test + @TestMetadata("entriesPropertyImportedClashOn.kt") + public void testEntriesPropertyImportedClashOn() throws Exception { + runTest("compiler/testData/diagnostics/tests/enum/entries/entriesPropertyImportedClashOn.kt"); + } + @Test @TestMetadata("entriesPropertyInCompanionClash.kt") public void testEntriesPropertyInCompanionClash() throws Exception { runTest("compiler/testData/diagnostics/tests/enum/entries/entriesPropertyInCompanionClash.kt"); } + @Test + @TestMetadata("entriesPropertyInCompanionClashOn.kt") + public void testEntriesPropertyInCompanionClashOn() throws Exception { + runTest("compiler/testData/diagnostics/tests/enum/entries/entriesPropertyInCompanionClashOn.kt"); + } + @Test @TestMetadata("entriesPropertyWithJvmStaticClash.kt") public void testEntriesPropertyWithJvmStaticClash() throws Exception { @@ -10439,11 +10457,23 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac runTest("compiler/testData/diagnostics/tests/enum/entries/nameShadowingOfExternallyDefinedEntries.kt"); } + @Test + @TestMetadata("nameShadowingOfExternallyDefinedEntriesOn.kt") + public void testNameShadowingOfExternallyDefinedEntriesOn() throws Exception { + runTest("compiler/testData/diagnostics/tests/enum/entries/nameShadowingOfExternallyDefinedEntriesOn.kt"); + } + @Test @TestMetadata("redeclarationOfEnumEntriesNameWithIntrinsic.kt") public void testRedeclarationOfEnumEntriesNameWithIntrinsic() throws Exception { runTest("compiler/testData/diagnostics/tests/enum/entries/redeclarationOfEnumEntriesNameWithIntrinsic.kt"); } + + @Test + @TestMetadata("redeclarationOfEnumEntriesNameWithIntrinsicOn.kt") + public void testRedeclarationOfEnumEntriesNameWithIntrinsicOn() throws Exception { + runTest("compiler/testData/diagnostics/tests/enum/entries/redeclarationOfEnumEntriesNameWithIntrinsicOn.kt"); + } } @Nested diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/CustomEnumEntriesMigrationCallChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/CustomEnumEntriesMigrationCallChecker.kt index c34ca8ee373..e3da9b560c0 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/CustomEnumEntriesMigrationCallChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/CustomEnumEntriesMigrationCallChecker.kt @@ -32,7 +32,12 @@ object CustomEnumEntriesMigrationCallChecker : CallChecker { ) { context.trace.report(Errors.DEPRECATED_ACCESS_TO_ENUM_ENTRY_COMPANION_PROPERTY.on(reportOn)) } else if (descriptor.isCallToExternalEntriesInsideEnum(reportOn)) { - context.trace.report(Errors.DEPRECATED_ACCESS_TO_ENTRY_PROPERTY_FROM_ENUM.on(reportOn)) + if (context.trace.bindingContext.diagnostics.forElement(reportOn).none { + it.factory == Errors.DEPRECATED_ACCESS_TO_ENTRY_PROPERTY_FROM_ENUM + } + ) { + context.trace.report(Errors.DEPRECATED_ACCESS_TO_ENTRY_PROPERTY_FROM_ENUM.on(reportOn)) + } } else if (descriptor.isReferenceToMemberEntriesWithoutExpectedFunctionalType(reportOn, context)) { context.trace.report(Errors.DEPRECATED_ACCESS_TO_ENUM_ENTRY_PROPERTY_AS_REFERENCE.on(reportOn)) } @@ -54,8 +59,9 @@ object CustomEnumEntriesMigrationCallChecker : CallChecker { } private fun PropertyDescriptor.isCallToExternalEntriesInsideEnum(contextExpression: PsiElement): Boolean { + val parent = contextExpression.parent return !DescriptorUtils.isEnumClass(this.containingDeclaration) && - contextExpression.parent !is KtDotQualifiedExpression && + (parent !is KtDotQualifiedExpression || parent.receiverExpression === contextExpression) && contextExpression.parentsWithSelf.any { it is KtClass && it.isEnum() } } diff --git a/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyAsExtensionClashOn.fir.kt b/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyAsExtensionClashOn.fir.kt new file mode 100644 index 00000000000..5be583fc22f --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyAsExtensionClashOn.fir.kt @@ -0,0 +1,29 @@ +// !LANGUAGE: +EnumEntries +// WITH_STDLIB + +package pckg + +enum class A { + ; + + companion object +} + +val A.Companion.entries: Int get() = 0 + +fun test() { + A.entries + A.Companion.entries + + with(A) { + this.entries + entries + } + + with(A.Companion) { + entries + } + + val aCompanion = A.Companion + aCompanion.entries +} diff --git a/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyAsExtensionClashOn.kt b/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyAsExtensionClashOn.kt new file mode 100644 index 00000000000..4b9211962af --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyAsExtensionClashOn.kt @@ -0,0 +1,29 @@ +// !LANGUAGE: +EnumEntries +// WITH_STDLIB + +package pckg + +enum class A { + ; + + companion object +} + +val A.Companion.entries: Int get() = 0 + +fun test() { + A.entries + A.Companion.entries + + with(A) { + this.entries + entries + } + + with(A.Companion) { + entries + } + + val aCompanion = A.Companion + aCompanion.entries +} diff --git a/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyAsExtensionClashOn.txt b/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyAsExtensionClashOn.txt new file mode 100644 index 00000000000..3df66f96b7d --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyAsExtensionClashOn.txt @@ -0,0 +1,31 @@ +package + +package pckg { + public val pckg.A.Companion.entries: kotlin.Int + public fun test(): kotlin.Unit + + public final enum class A : kotlin.Enum { + private constructor A() + @kotlin.internal.IntrinsicConstEvaluation 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: pckg.A): 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 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*/ val entries: kotlin.enums.EnumEntries + public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): pckg.A + public final /*synthesized*/ fun values(): kotlin.Array + } +} diff --git a/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyImportedClashOn.fir.kt b/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyImportedClashOn.fir.kt new file mode 100644 index 00000000000..b42536ec3fb --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyImportedClashOn.fir.kt @@ -0,0 +1,22 @@ +// !LANGUAGE: +EnumEntries +// WITH_STDLIB + +package foo + +import foo.A.Companion.entries + +enum class A { + ; + + companion object { + val entries = 0 + } +} + +fun test() { + A.entries + + with(A) { + entries + } +} diff --git a/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyImportedClashOn.kt b/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyImportedClashOn.kt new file mode 100644 index 00000000000..4e7cf48a404 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyImportedClashOn.kt @@ -0,0 +1,22 @@ +// !LANGUAGE: +EnumEntries +// WITH_STDLIB + +package foo + +import foo.A.Companion.entries + +enum class A { + ; + + companion object { + val entries = 0 + } +} + +fun test() { + A.entries + + with(A) { + entries + } +} diff --git a/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyImportedClashOn.txt b/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyImportedClashOn.txt new file mode 100644 index 00000000000..a791f876d40 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyImportedClashOn.txt @@ -0,0 +1,31 @@ +package + +package foo { + public fun test(): kotlin.Unit + + public final enum class A : kotlin.Enum { + private constructor A() + @kotlin.internal.IntrinsicConstEvaluation 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.A): 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 entries: kotlin.Int = 0 + 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*/ val entries: kotlin.enums.EnumEntries + public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): foo.A + public final /*synthesized*/ fun values(): kotlin.Array + } +} diff --git a/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyInCompanionClashOn.fir.kt b/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyInCompanionClashOn.fir.kt new file mode 100644 index 00000000000..9317dd9c5f0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyInCompanionClashOn.fir.kt @@ -0,0 +1,28 @@ +// !LANGUAGE: +EnumEntries +// WITH_STDLIB + +enum class A { + ; + + companion object { + val entries = 0 + } +} + +fun test() { + A.entries + A.Companion.entries + + with(A) { + entries + this.entries + values() // to be sure that we don't resolve into synthetic 'values' + } + + with(A.Companion) { + entries + } + + val aCompanion = A.Companion + aCompanion.entries +} diff --git a/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyInCompanionClashOn.kt b/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyInCompanionClashOn.kt new file mode 100644 index 00000000000..16b4edaebe7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyInCompanionClashOn.kt @@ -0,0 +1,28 @@ +// !LANGUAGE: +EnumEntries +// WITH_STDLIB + +enum class A { + ; + + companion object { + val entries = 0 + } +} + +fun test() { + A.entries + A.Companion.entries + + with(A) { + entries + this.entries + values() // to be sure that we don't resolve into synthetic 'values' + } + + with(A.Companion) { + entries + } + + val aCompanion = A.Companion + aCompanion.entries +} diff --git a/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyInCompanionClashOn.txt b/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyInCompanionClashOn.txt new file mode 100644 index 00000000000..75d73c2d3e7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyInCompanionClashOn.txt @@ -0,0 +1,29 @@ +package + +public fun test(): kotlin.Unit + +public final enum class A : kotlin.Enum { + private constructor A() + @kotlin.internal.IntrinsicConstEvaluation 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: A): 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 entries: kotlin.Int = 0 + 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*/ val entries: kotlin.enums.EnumEntries + public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): A + public final /*synthesized*/ fun values(): kotlin.Array +} diff --git a/compiler/testData/diagnostics/tests/enum/entries/enumEntriesAmbiguity.fir.kt b/compiler/testData/diagnostics/tests/enum/entries/enumEntriesAmbiguity.fir.kt index 7f8b3c3a87a..4f0f9084eae 100644 --- a/compiler/testData/diagnostics/tests/enum/entries/enumEntriesAmbiguity.fir.kt +++ b/compiler/testData/diagnostics/tests/enum/entries/enumEntriesAmbiguity.fir.kt @@ -6,4 +6,4 @@ enum class Ambiguous { first, entries; } -val e = Ambiguous.entries +val e = Ambiguous.entries.ordinal diff --git a/compiler/testData/diagnostics/tests/enum/entries/enumEntriesAmbiguity.fir.txt b/compiler/testData/diagnostics/tests/enum/entries/enumEntriesAmbiguity.fir.txt index a3612592e89..726ce1ed5af 100644 --- a/compiler/testData/diagnostics/tests/enum/entries/enumEntriesAmbiguity.fir.txt +++ b/compiler/testData/diagnostics/tests/enum/entries/enumEntriesAmbiguity.fir.txt @@ -16,5 +16,5 @@ FILE: enumEntriesAmbiguity.fir.kt public get(): R|kotlin/enums/EnumEntries| } - public final val e: R|Ambiguous| = Q|Ambiguous|.R|/Ambiguous.entries| - public get(): R|Ambiguous| + public final val e: R|kotlin/Int| = Q|Ambiguous|.R|/Ambiguous.entries|.R|SubstitutionOverride| + public get(): R|kotlin/Int| diff --git a/compiler/testData/diagnostics/tests/enum/entries/enumEntriesAmbiguity.kt b/compiler/testData/diagnostics/tests/enum/entries/enumEntriesAmbiguity.kt index c607c83174a..24be0845378 100644 --- a/compiler/testData/diagnostics/tests/enum/entries/enumEntriesAmbiguity.kt +++ b/compiler/testData/diagnostics/tests/enum/entries/enumEntriesAmbiguity.kt @@ -6,4 +6,4 @@ enum class Ambiguous { first, entries; } -val e = Ambiguous.entries +val e = Ambiguous.entries.ordinal diff --git a/compiler/testData/diagnostics/tests/enum/entries/enumEntriesAmbiguity.txt b/compiler/testData/diagnostics/tests/enum/entries/enumEntriesAmbiguity.txt index 61b0b236d01..f224cf3a622 100644 --- a/compiler/testData/diagnostics/tests/enum/entries/enumEntriesAmbiguity.txt +++ b/compiler/testData/diagnostics/tests/enum/entries/enumEntriesAmbiguity.txt @@ -1,6 +1,6 @@ package -public val e: Ambiguous +public val e: kotlin.Int public final enum class Ambiguous : kotlin.Enum { enum entry first diff --git a/compiler/testData/diagnostics/tests/enum/entries/nameShadowingOfExternallyDefinedEntriesOn.fir.kt b/compiler/testData/diagnostics/tests/enum/entries/nameShadowingOfExternallyDefinedEntriesOn.fir.kt new file mode 100644 index 00000000000..fc99b314de6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/entries/nameShadowingOfExternallyDefinedEntriesOn.fir.kt @@ -0,0 +1,40 @@ +// !LANGUAGE: +EnumEntries +// WITH_STDLIB + +package pckg + +val entries = "E" + +enum class E { + ; + + fun foo() { + entries.length + pckg.entries.length + } +} + +class A { + enum class E { + ; + + class B { + fun foo() { + entries.length + pckg.entries.length + } + } + + class C { + val entries = 0 + + fun foo() { + // technically, this warning is incorrect but I believe it's OK to report anyway + // first, logic in the compiler will be complicated if we'll try to avoid reporting warnings here + // second, this code smells, it'd be better to use qualifiers here anyway + entries + 4 + this.entries + 4 + } + } + } +} diff --git a/compiler/testData/diagnostics/tests/enum/entries/nameShadowingOfExternallyDefinedEntriesOn.kt b/compiler/testData/diagnostics/tests/enum/entries/nameShadowingOfExternallyDefinedEntriesOn.kt new file mode 100644 index 00000000000..4add5fc06f7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/entries/nameShadowingOfExternallyDefinedEntriesOn.kt @@ -0,0 +1,40 @@ +// !LANGUAGE: +EnumEntries +// WITH_STDLIB + +package pckg + +val entries = "E" + +enum class E { + ; + + fun foo() { + entries.length + pckg.entries.length + } +} + +class A { + enum class E { + ; + + class B { + fun foo() { + entries.length + pckg.entries.length + } + } + + class C { + val entries = 0 + + fun foo() { + // technically, this warning is incorrect but I believe it's OK to report anyway + // first, logic in the compiler will be complicated if we'll try to avoid reporting warnings here + // second, this code smells, it'd be better to use qualifiers here anyway + entries + 4 + this.entries + 4 + } + } + } +} diff --git a/compiler/testData/diagnostics/tests/enum/entries/nameShadowingOfExternallyDefinedEntriesOn.txt b/compiler/testData/diagnostics/tests/enum/entries/nameShadowingOfExternallyDefinedEntriesOn.txt new file mode 100644 index 00000000000..b753e66ed53 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/entries/nameShadowingOfExternallyDefinedEntriesOn.txt @@ -0,0 +1,66 @@ +package + +package pckg { + public val entries: kotlin.String = "E" + + public final class A { + public constructor A() + 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 + + public final enum class E : kotlin.Enum { + private constructor E() + @kotlin.internal.IntrinsicConstEvaluation 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: pckg.A.E): 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 final class B { + public constructor B() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final fun foo(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + public final class C { + public constructor C() + public final val entries: kotlin.Int = 0 + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final fun foo(): kotlin.Unit + 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*/ val entries: kotlin.enums.EnumEntries + public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): pckg.A.E + public final /*synthesized*/ fun values(): kotlin.Array + } + } + + public final enum class E : kotlin.Enum { + private constructor E() + @kotlin.internal.IntrinsicConstEvaluation 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: pckg.E): 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 fun foo(): 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 + + // Static members + public final /*synthesized*/ val entries: kotlin.enums.EnumEntries + public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): pckg.E + public final /*synthesized*/ fun values(): kotlin.Array + } +} diff --git a/compiler/testData/diagnostics/tests/enum/entries/redeclarationOfEnumEntriesNameWithIntrinsicOn.fir.kt b/compiler/testData/diagnostics/tests/enum/entries/redeclarationOfEnumEntriesNameWithIntrinsicOn.fir.kt new file mode 100644 index 00000000000..4b02d594a73 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/entries/redeclarationOfEnumEntriesNameWithIntrinsicOn.fir.kt @@ -0,0 +1,11 @@ +// !LANGUAGE: +EnumEntries +// WITH_STDLIB + +enum class E { + entries, Entries; + + fun foo() { + entries.ordinal + E.entries.ordinal + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/enum/entries/redeclarationOfEnumEntriesNameWithIntrinsicOn.kt b/compiler/testData/diagnostics/tests/enum/entries/redeclarationOfEnumEntriesNameWithIntrinsicOn.kt new file mode 100644 index 00000000000..5149ad269f7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/entries/redeclarationOfEnumEntriesNameWithIntrinsicOn.kt @@ -0,0 +1,11 @@ +// !LANGUAGE: +EnumEntries +// WITH_STDLIB + +enum class E { + entries, Entries; + + fun foo() { + entries.ordinal + E.entries.ordinal + } +} diff --git a/compiler/testData/diagnostics/tests/enum/entries/redeclarationOfEnumEntriesNameWithIntrinsicOn.txt b/compiler/testData/diagnostics/tests/enum/entries/redeclarationOfEnumEntriesNameWithIntrinsicOn.txt new file mode 100644 index 00000000000..3989bd1962c --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/entries/redeclarationOfEnumEntriesNameWithIntrinsicOn.txt @@ -0,0 +1,24 @@ +package + +public final enum class E : kotlin.Enum { + enum entry entries + + enum entry Entries + + private constructor E() + @kotlin.internal.IntrinsicConstEvaluation 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: E): 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 fun foo(): 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 + + // Static members + public final /*synthesized*/ val entries: kotlin.enums.EnumEntries + public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): E + public final /*synthesized*/ fun values(): kotlin.Array +} diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index 9107d76b778..d4e2f1b30a9 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -10397,18 +10397,36 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/enum/entries/entriesPropertyAsExtensionClash.kt"); } + @Test + @TestMetadata("entriesPropertyAsExtensionClashOn.kt") + public void testEntriesPropertyAsExtensionClashOn() throws Exception { + runTest("compiler/testData/diagnostics/tests/enum/entries/entriesPropertyAsExtensionClashOn.kt"); + } + @Test @TestMetadata("entriesPropertyImportedClash.kt") public void testEntriesPropertyImportedClash() throws Exception { runTest("compiler/testData/diagnostics/tests/enum/entries/entriesPropertyImportedClash.kt"); } + @Test + @TestMetadata("entriesPropertyImportedClashOn.kt") + public void testEntriesPropertyImportedClashOn() throws Exception { + runTest("compiler/testData/diagnostics/tests/enum/entries/entriesPropertyImportedClashOn.kt"); + } + @Test @TestMetadata("entriesPropertyInCompanionClash.kt") public void testEntriesPropertyInCompanionClash() throws Exception { runTest("compiler/testData/diagnostics/tests/enum/entries/entriesPropertyInCompanionClash.kt"); } + @Test + @TestMetadata("entriesPropertyInCompanionClashOn.kt") + public void testEntriesPropertyInCompanionClashOn() throws Exception { + runTest("compiler/testData/diagnostics/tests/enum/entries/entriesPropertyInCompanionClashOn.kt"); + } + @Test @TestMetadata("entriesPropertyWithJvmStaticClash.kt") public void testEntriesPropertyWithJvmStaticClash() throws Exception { @@ -10445,11 +10463,23 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/enum/entries/nameShadowingOfExternallyDefinedEntries.kt"); } + @Test + @TestMetadata("nameShadowingOfExternallyDefinedEntriesOn.kt") + public void testNameShadowingOfExternallyDefinedEntriesOn() throws Exception { + runTest("compiler/testData/diagnostics/tests/enum/entries/nameShadowingOfExternallyDefinedEntriesOn.kt"); + } + @Test @TestMetadata("redeclarationOfEnumEntriesNameWithIntrinsic.kt") public void testRedeclarationOfEnumEntriesNameWithIntrinsic() throws Exception { runTest("compiler/testData/diagnostics/tests/enum/entries/redeclarationOfEnumEntriesNameWithIntrinsic.kt"); } + + @Test + @TestMetadata("redeclarationOfEnumEntriesNameWithIntrinsicOn.kt") + public void testRedeclarationOfEnumEntriesNameWithIntrinsicOn() throws Exception { + runTest("compiler/testData/diagnostics/tests/enum/entries/redeclarationOfEnumEntriesNameWithIntrinsicOn.kt"); + } } @Nested