Add a warning for a custom Enum.entries entry
^KT-53153
This commit is contained in:
committed by
Space Team
parent
989fc886e1
commit
c70a1b1884
+6
@@ -10354,6 +10354,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
|
||||
public void testGenericEntriesPropertyClash() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/enum/entries/genericEntriesPropertyClash.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("redeclarationOfEnumEntriesNameWithIntrinsic.kt")
|
||||
public void testRedeclarationOfEnumEntriesNameWithIntrinsic() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/enum/entries/redeclarationOfEnumEntriesNameWithIntrinsic.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
|
||||
+6
@@ -10360,6 +10360,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
||||
public void testGenericEntriesPropertyClash() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/enum/entries/genericEntriesPropertyClash.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("redeclarationOfEnumEntriesNameWithIntrinsic.kt")
|
||||
public void testRedeclarationOfEnumEntriesNameWithIntrinsic() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/enum/entries/redeclarationOfEnumEntriesNameWithIntrinsic.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
|
||||
+6
@@ -10354,6 +10354,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
||||
public void testGenericEntriesPropertyClash() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/enum/entries/genericEntriesPropertyClash.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("redeclarationOfEnumEntriesNameWithIntrinsic.kt")
|
||||
public void testRedeclarationOfEnumEntriesNameWithIntrinsic() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/enum/entries/redeclarationOfEnumEntriesNameWithIntrinsic.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
|
||||
@@ -143,6 +143,7 @@ public interface Errors {
|
||||
DiagnosticFactory1<PsiElement, PropertyDescriptor> DEPRECATED_ACCESS_TO_ENUM_COMPANION_PROPERTY = DiagnosticFactory1.create(WARNING);
|
||||
|
||||
DiagnosticFactory0<PsiElement> DEPRECATED_ACCESS_TO_ENUM_ENTRY_COMPANION_PROPERTY = DiagnosticFactory0.create(WARNING);
|
||||
DiagnosticFactory0<KtEnumEntry> DEPRECATED_DECLARATION_OF_ENUM_ENTRY = DiagnosticFactory0.create(WARNING);
|
||||
|
||||
DiagnosticFactory2<PsiElement, PropertyDescriptor, ClassDescriptor> DEPRECATED_RESOLVE_WITH_AMBIGUOUS_ENUM_ENTRY = DiagnosticFactory2.create(WARNING);
|
||||
|
||||
|
||||
+1
@@ -74,6 +74,7 @@ public class DefaultErrorMessages {
|
||||
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_DECLARATION_OF_ENUM_ENTRY, "Conflicting declarations: enum entry 'entries' and the property 'Enum.entries' (KT-48872). Please, rename the enum entry declaration");
|
||||
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);
|
||||
|
||||
@@ -54,6 +54,7 @@ private val DEFAULT_DECLARATION_CHECKERS = listOf(
|
||||
CyclicAnnotationsChecker,
|
||||
UnsupportedUntilRangeDeclarationChecker,
|
||||
DataObjectContentChecker,
|
||||
EnumEntriesRedeclarationChecker,
|
||||
)
|
||||
|
||||
private val DEFAULT_CALL_CHECKERS = listOf(
|
||||
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2010-2023 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.checkers
|
||||
|
||||
import org.jetbrains.kotlin.builtins.StandardNames
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.diagnostics.Errors
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtEnumEntry
|
||||
|
||||
object EnumEntriesRedeclarationChecker : DeclarationChecker {
|
||||
override fun check(declaration: KtDeclaration, descriptor: DeclarationDescriptor, context: DeclarationCheckerContext) {
|
||||
if (declaration !is KtEnumEntry || declaration.name != StandardNames.ENUM_ENTRIES.asString()) return
|
||||
|
||||
context.trace.report(Errors.DEPRECATED_DECLARATION_OF_ENUM_ENTRY.on(declaration))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// !LANGUAGE: +EnumEntries
|
||||
// FIR_DUMP
|
||||
|
||||
enum class Ambiguous {
|
||||
first, entries;
|
||||
}
|
||||
|
||||
val e = Ambiguous.entries
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
FILE: enumEntriesAmbiguity.kt
|
||||
FILE: enumEntriesAmbiguity.fir.kt
|
||||
public final enum class Ambiguous : R|kotlin/Enum<Ambiguous>| {
|
||||
private constructor(): R|Ambiguous| {
|
||||
super<R|kotlin/Enum<Ambiguous>|>()
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
// FIR_IDENTICAL
|
||||
// !LANGUAGE: +EnumEntries
|
||||
// FIR_DUMP
|
||||
|
||||
enum class Ambiguous {
|
||||
first, entries;
|
||||
first, <!DEPRECATED_DECLARATION_OF_ENUM_ENTRY!>entries;<!>
|
||||
}
|
||||
|
||||
val e = Ambiguous.entries
|
||||
|
||||
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
// !LANGUAGE: -EnumEntries
|
||||
|
||||
enum class E {
|
||||
entries, Entries;
|
||||
|
||||
fun foo() {
|
||||
entries
|
||||
E.entries
|
||||
}
|
||||
}
|
||||
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
// !LANGUAGE: -EnumEntries
|
||||
|
||||
enum class E {
|
||||
<!DEPRECATED_DECLARATION_OF_ENUM_ENTRY!>entries,<!> Entries;
|
||||
|
||||
fun foo() {
|
||||
entries
|
||||
E.entries
|
||||
}
|
||||
}
|
||||
Vendored
+23
@@ -0,0 +1,23 @@
|
||||
package
|
||||
|
||||
public final enum class E : kotlin.Enum<E> {
|
||||
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<E!>!
|
||||
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): E
|
||||
public final /*synthesized*/ fun values(): kotlin.Array<E>
|
||||
}
|
||||
Generated
+6
@@ -10360,6 +10360,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
public void testGenericEntriesPropertyClash() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/enum/entries/genericEntriesPropertyClash.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("redeclarationOfEnumEntriesNameWithIntrinsic.kt")
|
||||
public void testRedeclarationOfEnumEntriesNameWithIntrinsic() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/enum/entries/redeclarationOfEnumEntriesNameWithIntrinsic.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
|
||||
Reference in New Issue
Block a user