[FE 1.0] Don't report deprecation diagnostics about enum on it's own entries

^KT-37975 Fixed
This commit is contained in:
Dmitriy Novozhilov
2021-12-06 15:40:30 +03:00
committed by teamcity
parent 6b327d2380
commit b2b5f4a63a
8 changed files with 67 additions and 0 deletions
@@ -8873,6 +8873,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
runTest("compiler/testData/diagnostics/tests/deprecated/unusedImport.kt");
}
@Test
@TestMetadata("usageOnEnum.kt")
public void testUsageOnEnum() throws Exception {
runTest("compiler/testData/diagnostics/tests/deprecated/usageOnEnum.kt");
}
@Test
@TestMetadata("warningOnConstructorErrorOnClass.kt")
public void testWarningOnConstructorErrorOnClass() throws Exception {
@@ -8873,6 +8873,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
runTest("compiler/testData/diagnostics/tests/deprecated/unusedImport.kt");
}
@Test
@TestMetadata("usageOnEnum.kt")
public void testUsageOnEnum() throws Exception {
runTest("compiler/testData/diagnostics/tests/deprecated/usageOnEnum.kt");
}
@Test
@TestMetadata("warningOnConstructorErrorOnClass.kt")
public void testWarningOnConstructorErrorOnClass() throws Exception {
@@ -8873,6 +8873,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
runTest("compiler/testData/diagnostics/tests/deprecated/unusedImport.kt");
}
@Test
@TestMetadata("usageOnEnum.kt")
public void testUsageOnEnum() throws Exception {
runTest("compiler/testData/diagnostics/tests/deprecated/usageOnEnum.kt");
}
@Test
@TestMetadata("warningOnConstructorErrorOnClass.kt")
public void testWarningOnConstructorErrorOnClass() throws Exception {
@@ -17,14 +17,27 @@
package org.jetbrains.kotlin.resolve.checkers
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
import org.jetbrains.kotlin.descriptors.ConstructorDescriptor
import org.jetbrains.kotlin.psi.KtEnumEntrySuperclassReferenceExpression
import org.jetbrains.kotlin.psi.KtThisExpression
import org.jetbrains.kotlin.psi.synthetics.findClassDescriptor
import org.jetbrains.kotlin.resolve.calls.util.getResolvedCall
import org.jetbrains.kotlin.resolve.deprecation.createDeprecationDiagnostic
class DeprecatedClassifierUsageChecker : ClassifierUsageChecker {
override fun check(targetDescriptor: ClassifierDescriptor, element: PsiElement, context: ClassifierUsageCheckerContext) {
if (element.parent is KtThisExpression) return
if (context.languageVersionSettings.supportsFeature(LanguageFeature.NoDeprecationOnDeprecatedEnumEntries) && element is KtEnumEntrySuperclassReferenceExpression) {
val referencedEnum =
(element.getResolvedCall(context.trace.bindingContext)?.resultingDescriptor as? ConstructorDescriptor)?.constructedClass
if (referencedEnum == targetDescriptor) {
return
}
}
for (deprecation in context.deprecationResolver.getDeprecations(targetDescriptor)) {
context.trace.report(createDeprecationDiagnostic(element, deprecation, context.languageVersionSettings))
}
@@ -0,0 +1,8 @@
// FIR_IDENTICAL
// LANGUAGE: +NoDeprecationOnDeprecatedEnumEntries
// ISSUE: KT-37975
@Deprecated("")
enum class Foo(val x: Int) {
A(42)
}
@@ -0,0 +1,21 @@
package
@kotlin.Deprecated(message = "") public final enum class Foo : kotlin.Enum<Foo> {
enum entry A
private constructor Foo(/*0*/ x: 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 x: 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<Foo!>!
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): Foo
public final /*synthesized*/ fun values(): kotlin.Array<Foo>
}
@@ -8879,6 +8879,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/deprecated/unusedImport.kt");
}
@Test
@TestMetadata("usageOnEnum.kt")
public void testUsageOnEnum() throws Exception {
runTest("compiler/testData/diagnostics/tests/deprecated/usageOnEnum.kt");
}
@Test
@TestMetadata("warningOnConstructorErrorOnClass.kt")
public void testWarningOnConstructorErrorOnClass() throws Exception {
@@ -246,6 +246,7 @@ enum class LanguageFeature(
InlineClassImplementationByDelegation(KOTLIN_1_7),
QualifiedSupertypeMayBeExtendedByOtherSupertype(KOTLIN_1_7),
YieldIsNoMoreReserved(KOTLIN_1_7),
NoDeprecationOnDeprecatedEnumEntries(KOTLIN_1_7), // KT-37975
// 1.8