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 4fffd601226..cb45ecc107e 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 @@ -10319,11 +10319,41 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/enum/entries"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); } + @Test + @TestMetadata("entriesPropertyAsExtensionClash.kt") + public void testEntriesPropertyAsExtensionClash() throws Exception { + runTest("compiler/testData/diagnostics/tests/enum/entries/entriesPropertyAsExtensionClash.kt"); + } + + @Test + @TestMetadata("entriesPropertyImportedClash.kt") + public void testEntriesPropertyImportedClash() throws Exception { + runTest("compiler/testData/diagnostics/tests/enum/entries/entriesPropertyImportedClash.kt"); + } + + @Test + @TestMetadata("entriesPropertyInCompanionClash.kt") + public void testEntriesPropertyInCompanionClash() throws Exception { + runTest("compiler/testData/diagnostics/tests/enum/entries/entriesPropertyInCompanionClash.kt"); + } + + @Test + @TestMetadata("entriesPropertyWithJvmStaticClash.kt") + public void testEntriesPropertyWithJvmStaticClash() throws Exception { + runTest("compiler/testData/diagnostics/tests/enum/entries/entriesPropertyWithJvmStaticClash.kt"); + } + @Test @TestMetadata("enumEntriesAmbiguity.kt") public void testEnumEntriesAmbiguity() throws Exception { runTest("compiler/testData/diagnostics/tests/enum/entries/enumEntriesAmbiguity.kt"); } + + @Test + @TestMetadata("genericEntriesPropertyClash.kt") + public void testGenericEntriesPropertyClash() throws Exception { + runTest("compiler/testData/diagnostics/tests/enum/entries/genericEntriesPropertyClash.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 c1fbb2d1fe1..e45c7518654 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 @@ -10325,11 +10325,41 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/enum/entries"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); } + @Test + @TestMetadata("entriesPropertyAsExtensionClash.kt") + public void testEntriesPropertyAsExtensionClash() throws Exception { + runTest("compiler/testData/diagnostics/tests/enum/entries/entriesPropertyAsExtensionClash.kt"); + } + + @Test + @TestMetadata("entriesPropertyImportedClash.kt") + public void testEntriesPropertyImportedClash() throws Exception { + runTest("compiler/testData/diagnostics/tests/enum/entries/entriesPropertyImportedClash.kt"); + } + + @Test + @TestMetadata("entriesPropertyInCompanionClash.kt") + public void testEntriesPropertyInCompanionClash() throws Exception { + runTest("compiler/testData/diagnostics/tests/enum/entries/entriesPropertyInCompanionClash.kt"); + } + + @Test + @TestMetadata("entriesPropertyWithJvmStaticClash.kt") + public void testEntriesPropertyWithJvmStaticClash() throws Exception { + runTest("compiler/testData/diagnostics/tests/enum/entries/entriesPropertyWithJvmStaticClash.kt"); + } + @Test @TestMetadata("enumEntriesAmbiguity.kt") public void testEnumEntriesAmbiguity() throws Exception { runTest("compiler/testData/diagnostics/tests/enum/entries/enumEntriesAmbiguity.kt"); } + + @Test + @TestMetadata("genericEntriesPropertyClash.kt") + public void testGenericEntriesPropertyClash() throws Exception { + runTest("compiler/testData/diagnostics/tests/enum/entries/genericEntriesPropertyClash.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 ed1b70c029e..43aacdd0e60 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 @@ -10319,11 +10319,41 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/enum/entries"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); } + @Test + @TestMetadata("entriesPropertyAsExtensionClash.kt") + public void testEntriesPropertyAsExtensionClash() throws Exception { + runTest("compiler/testData/diagnostics/tests/enum/entries/entriesPropertyAsExtensionClash.kt"); + } + + @Test + @TestMetadata("entriesPropertyImportedClash.kt") + public void testEntriesPropertyImportedClash() throws Exception { + runTest("compiler/testData/diagnostics/tests/enum/entries/entriesPropertyImportedClash.kt"); + } + + @Test + @TestMetadata("entriesPropertyInCompanionClash.kt") + public void testEntriesPropertyInCompanionClash() throws Exception { + runTest("compiler/testData/diagnostics/tests/enum/entries/entriesPropertyInCompanionClash.kt"); + } + + @Test + @TestMetadata("entriesPropertyWithJvmStaticClash.kt") + public void testEntriesPropertyWithJvmStaticClash() throws Exception { + runTest("compiler/testData/diagnostics/tests/enum/entries/entriesPropertyWithJvmStaticClash.kt"); + } + @Test @TestMetadata("enumEntriesAmbiguity.kt") public void testEnumEntriesAmbiguity() throws Exception { runTest("compiler/testData/diagnostics/tests/enum/entries/enumEntriesAmbiguity.kt"); } + + @Test + @TestMetadata("genericEntriesPropertyClash.kt") + public void testGenericEntriesPropertyClash() throws Exception { + runTest("compiler/testData/diagnostics/tests/enum/entries/genericEntriesPropertyClash.kt"); + } } @Nested diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index c1d66e5eb7f..e207ee0bdc4 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -142,6 +142,8 @@ public interface Errors { DiagnosticFactory1 DEPRECATED_ACCESS_TO_ENUM_COMPANION_PROPERTY = DiagnosticFactory1.create(WARNING); + DiagnosticFactory0 DEPRECATED_ACCESS_TO_ENUM_ENTRY_COMPANION_PROPERTY = DiagnosticFactory0.create(WARNING); + DiagnosticFactory2 DEPRECATED_RESOLVE_WITH_AMBIGUOUS_ENUM_ENTRY = DiagnosticFactory2.create(WARNING); DiagnosticFactory1 PROTECTED_CONSTRUCTOR_NOT_IN_SUPER_CALL = DiagnosticFactory1.create(ERROR); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java index 70ee8a9c71e..bad48decd91 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -73,6 +73,7 @@ public class DefaultErrorMessages { MAP.put(INVISIBLE_MEMBER, "Cannot access ''{0}'': it is {1} in {2}", NAME, VISIBILITY, NAME_OF_CONTAINING_DECLARATION_OR_FILE); MAP.put(DEPRECATED_ACCESS_BY_SHORT_NAME, "Access to this type by short name is deprecated, and soon is going to be removed. Please, add explicit qualifier or import", NAME); MAP.put(DEPRECATED_ACCESS_TO_ENUM_COMPANION_PROPERTY, "Ambiguous access to companion''s property ''{0}'' in enum is deprecated. Please, add explicit Companion qualifier to the class name", NAME); + MAP.put(DEPRECATED_ACCESS_TO_ENUM_ENTRY_COMPANION_PROPERTY, "Ambiguous access to companion''s property 'entries' in enum is deprecated. Please, add explicit Companion qualifier to the class name"); MAP.put(DEPRECATED_RESOLVE_WITH_AMBIGUOUS_ENUM_ENTRY, "Ambiguous access to property ''{0}'' is deprecated because similar enum entry ''{1}'' is available. Please add explicit named import or use fully qualified name", FQ_NAME, FQ_NAME); MAP.put(PROTECTED_CONSTRUCTOR_NOT_IN_SUPER_CALL, "Protected constructor ''{0}'' from other classes can only be used in super-call", Renderers.SHORT_NAMES_IN_TYPES); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/PlatformConfiguratorBase.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/PlatformConfiguratorBase.kt index 7e76e770607..efc8df86de5 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/PlatformConfiguratorBase.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/PlatformConfiguratorBase.kt @@ -72,6 +72,7 @@ private val DEFAULT_CALL_CHECKERS = listOf( NewSchemeOfIntegerOperatorResolutionChecker, EnumEntryVsCompanionPriorityCallChecker, CompanionInParenthesesLHSCallChecker, ResolutionToPrivateConstructorOfSealedClassChecker, EqualityCallChecker, UnsupportedUntilOperatorChecker, BuilderInferenceAssignmentChecker, IncorrectCapturedApproximationCallChecker, CompanionIncorrectlyUnboundedWhenUsedAsLHSCallChecker, + CustomEnumEntriesMigrationCallChecker, ) private val DEFAULT_TYPE_CHECKERS = emptyList() private val DEFAULT_CLASSIFIER_USAGE_CHECKERS = listOf( 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 new file mode 100644 index 00000000000..0b44a9e51d5 --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/CustomEnumEntriesMigrationCallChecker.kt @@ -0,0 +1,46 @@ +/* + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.resolve.calls.checkers + +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.builtins.StandardNames +import org.jetbrains.kotlin.descriptors.ClassDescriptor +import org.jetbrains.kotlin.descriptors.PropertyDescriptor +import org.jetbrains.kotlin.diagnostics.Errors +import org.jetbrains.kotlin.resolve.DescriptorUtils +import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall +import org.jetbrains.kotlin.resolve.descriptorUtil.isCompanionObject +import org.jetbrains.kotlin.resolve.scopes.receivers.ClassValueReceiver +import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue + +object CustomEnumEntriesMigrationCallChecker : CallChecker { + override fun check(resolvedCall: ResolvedCall<*>, reportOn: PsiElement, context: CallCheckerContext) { + val descriptor = resolvedCall.resultingDescriptor + if (descriptor !is PropertyDescriptor) return + if (descriptor.name != StandardNames.ENUM_ENTRIES) return + + if (resolvedCall.isExtensionWithEnumClassQualifier() || + resolvedCall.isCallViaCompanionOnEnumClassQualifier(descriptor) + ) { + context.trace.report(Errors.DEPRECATED_ACCESS_TO_ENUM_ENTRY_COMPANION_PROPERTY.on(reportOn)) + } + } + + private fun ResolvedCall<*>.isExtensionWithEnumClassQualifier(): Boolean { + val receiver = extensionReceiver ?: return false + return receiver is ClassValueReceiver && DescriptorUtils.isEnumClass(receiver.classQualifier.descriptor) + } + + private fun ResolvedCall<*>.isCallViaCompanionOnEnumClassQualifier(descriptor: PropertyDescriptor): Boolean { + val containingDeclaration = descriptor.containingDeclaration + if (!containingDeclaration.isCompanionObject()) return false + + val grandParent = containingDeclaration.containingDeclaration ?: return false + if (grandParent !is ClassDescriptor || !DescriptorUtils.isEnumClass(grandParent)) return false + + return dispatchReceiver.isQualifierFor(grandParent) + } +} \ No newline at end of file diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/EnumEntryVsCompanionPriorityCallChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/EnumEntryVsCompanionPriorityCallChecker.kt index 9e79ab6e25a..b1830508061 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/EnumEntryVsCompanionPriorityCallChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/EnumEntryVsCompanionPriorityCallChecker.kt @@ -43,10 +43,10 @@ object EnumEntryVsCompanionPriorityCallChecker : CallChecker { val foundDescriptor = unsubstitutedMemberScope.getContributedClassifier(name, NoLookupLocation.FOR_ALREADY_TRACKED) return foundDescriptor is ClassDescriptor && foundDescriptor.kind == ClassKind.ENUM_ENTRY } - - private fun ReceiverValue?.isQualifierFor(classDescriptor: ClassDescriptor): Boolean { - if (this !is ClassValueReceiver) return false - val thisClass = this.classQualifier.descriptor as? ClassDescriptor ?: return false - return thisClass.typeConstructor == classDescriptor.typeConstructor - } +} + +internal fun ReceiverValue?.isQualifierFor(classDescriptor: ClassDescriptor): Boolean { + if (this !is ClassValueReceiver) return false + val thisClass = this.classQualifier.descriptor as? ClassDescriptor ?: return false + return thisClass.typeConstructor == classDescriptor.typeConstructor } diff --git a/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyAsExtensionClash.fir.kt b/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyAsExtensionClash.fir.kt new file mode 100644 index 00000000000..dee3cf9673f --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyAsExtensionClash.fir.kt @@ -0,0 +1,28 @@ +// !LANGUAGE: -EnumEntries + +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 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyAsExtensionClash.kt b/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyAsExtensionClash.kt new file mode 100644 index 00000000000..583d075e0b1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyAsExtensionClash.kt @@ -0,0 +1,28 @@ +// !LANGUAGE: -EnumEntries + +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 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyAsExtensionClash.txt b/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyAsExtensionClash.txt new file mode 100644 index 00000000000..3efedb749a5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyAsExtensionClash.txt @@ -0,0 +1,30 @@ +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*/ fun valueOf(/*0*/ value: kotlin.String): pckg.A + public final /*synthesized*/ fun values(): kotlin.Array + } +} diff --git a/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyImportedClash.fir.kt b/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyImportedClash.fir.kt new file mode 100644 index 00000000000..aeb4220ac83 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyImportedClash.fir.kt @@ -0,0 +1,21 @@ +// !LANGUAGE: -EnumEntries + +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/entriesPropertyImportedClash.kt b/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyImportedClash.kt new file mode 100644 index 00000000000..030e195cb14 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyImportedClash.kt @@ -0,0 +1,21 @@ +// !LANGUAGE: -EnumEntries + +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/entriesPropertyImportedClash.txt b/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyImportedClash.txt new file mode 100644 index 00000000000..ff2a24b0450 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyImportedClash.txt @@ -0,0 +1,30 @@ +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*/ fun valueOf(/*0*/ value: kotlin.String): foo.A + public final /*synthesized*/ fun values(): kotlin.Array + } +} diff --git a/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyInCompanionClash.fir.kt b/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyInCompanionClash.fir.kt new file mode 100644 index 00000000000..b2651e2d518 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyInCompanionClash.fir.kt @@ -0,0 +1,27 @@ +// !LANGUAGE: -EnumEntries + +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/entriesPropertyInCompanionClash.kt b/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyInCompanionClash.kt new file mode 100644 index 00000000000..6f395405e0b --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyInCompanionClash.kt @@ -0,0 +1,27 @@ +// !LANGUAGE: -EnumEntries + +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/entriesPropertyInCompanionClash.txt b/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyInCompanionClash.txt new file mode 100644 index 00000000000..11a7c0bc0b0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyInCompanionClash.txt @@ -0,0 +1,28 @@ +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*/ fun valueOf(/*0*/ value: kotlin.String): A + public final /*synthesized*/ fun values(): kotlin.Array +} diff --git a/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyWithJvmStaticClash.fir.kt b/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyWithJvmStaticClash.fir.kt new file mode 100644 index 00000000000..2bcb091cb75 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyWithJvmStaticClash.fir.kt @@ -0,0 +1,21 @@ +// !LANGUAGE: -EnumEntries +// WITH_STDLIB + +enum class A { + ; + + companion object { + @JvmStatic + val entries = 0 + } +} + +fun test() { + A.entries + + with(A) { + entries + } + + A.Companion.entries +} diff --git a/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyWithJvmStaticClash.kt b/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyWithJvmStaticClash.kt new file mode 100644 index 00000000000..021b7d031d9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyWithJvmStaticClash.kt @@ -0,0 +1,21 @@ +// !LANGUAGE: -EnumEntries +// WITH_STDLIB + +enum class A { + ; + + companion object { + @JvmStatic + val entries = 0 + } +} + +fun test() { + A.entries + + with(A) { + entries + } + + A.Companion.entries +} diff --git a/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyWithJvmStaticClash.txt b/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyWithJvmStaticClash.txt new file mode 100644 index 00000000000..1c38ee3f160 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/entries/entriesPropertyWithJvmStaticClash.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() + @kotlin.jvm.JvmStatic 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/genericEntriesPropertyClash.fir.kt b/compiler/testData/diagnostics/tests/enum/entries/genericEntriesPropertyClash.fir.kt new file mode 100644 index 00000000000..721aad99138 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/entries/genericEntriesPropertyClash.fir.kt @@ -0,0 +1,16 @@ +// !LANGUAGE: -EnumEntries + +package pckg + +enum class A { + ; + + companion object +} + +val T.entries: Int get() = 0 + +fun test() { + A.entries + A.Companion.entries +} diff --git a/compiler/testData/diagnostics/tests/enum/entries/genericEntriesPropertyClash.kt b/compiler/testData/diagnostics/tests/enum/entries/genericEntriesPropertyClash.kt new file mode 100644 index 00000000000..088f81f2192 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/entries/genericEntriesPropertyClash.kt @@ -0,0 +1,16 @@ +// !LANGUAGE: -EnumEntries + +package pckg + +enum class A { + ; + + companion object +} + +val T.entries: Int get() = 0 + +fun test() { + A.entries + A.Companion.entries +} diff --git a/compiler/testData/diagnostics/tests/enum/entries/genericEntriesPropertyClash.txt b/compiler/testData/diagnostics/tests/enum/entries/genericEntriesPropertyClash.txt new file mode 100644 index 00000000000..6746c72b36e --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/entries/genericEntriesPropertyClash.txt @@ -0,0 +1,30 @@ +package + +package pckg { + public val T.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*/ fun valueOf(/*0*/ value: kotlin.String): pckg.A + 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 7cbbd95238a..676d1e9df88 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 @@ -10325,11 +10325,41 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/enum/entries"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); } + @Test + @TestMetadata("entriesPropertyAsExtensionClash.kt") + public void testEntriesPropertyAsExtensionClash() throws Exception { + runTest("compiler/testData/diagnostics/tests/enum/entries/entriesPropertyAsExtensionClash.kt"); + } + + @Test + @TestMetadata("entriesPropertyImportedClash.kt") + public void testEntriesPropertyImportedClash() throws Exception { + runTest("compiler/testData/diagnostics/tests/enum/entries/entriesPropertyImportedClash.kt"); + } + + @Test + @TestMetadata("entriesPropertyInCompanionClash.kt") + public void testEntriesPropertyInCompanionClash() throws Exception { + runTest("compiler/testData/diagnostics/tests/enum/entries/entriesPropertyInCompanionClash.kt"); + } + + @Test + @TestMetadata("entriesPropertyWithJvmStaticClash.kt") + public void testEntriesPropertyWithJvmStaticClash() throws Exception { + runTest("compiler/testData/diagnostics/tests/enum/entries/entriesPropertyWithJvmStaticClash.kt"); + } + @Test @TestMetadata("enumEntriesAmbiguity.kt") public void testEnumEntriesAmbiguity() throws Exception { runTest("compiler/testData/diagnostics/tests/enum/entries/enumEntriesAmbiguity.kt"); } + + @Test + @TestMetadata("genericEntriesPropertyClash.kt") + public void testGenericEntriesPropertyClash() throws Exception { + runTest("compiler/testData/diagnostics/tests/enum/entries/genericEntriesPropertyClash.kt"); + } } @Nested