From 093695962a13d0fe723fc3377f0dbfdf3c16df6e Mon Sep 17 00:00:00 2001 From: Dmitrii Gridin Date: Mon, 3 Apr 2023 19:17:33 +0200 Subject: [PATCH] [FIR] hacky fix lazy resolve contract violation for deprecation of enum entries Enum entries can be used as types in Kotlin (even it's a compilation error) To use the classifier as a type, we need to find if it's hidden or not. The deprecations for classes are calculated on COMPILER_REQUIRED_ANNOTATION phase, and that's okay as it goes before the TYPES phase. For enum entries, the deprecations are calculated on TYPES phase which goes on TYPES phase. This is incorrect as we cannot jump from lower phase to upper phase The hack ignores such deprecation search for enum entires. Test: org.jetbrains.kotlin.analysis.low.level.api.fir.diagnostic.compiler.based.LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.Tests.testEnumEntryAsType ^KT-57648 ^KT-56543 --- .../fir/resolve/providers/impl/FirTypeResolverImpl.kt | 10 +++++++++- .../testData/diagnostics/tests/EnumEntryAsType.fir.kt | 1 - compiler/testData/diagnostics/tests/EnumEntryAsType.kt | 1 - .../diagnostics/tests/enum/inheritFromEnumEntry.kt | 1 - 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/providers/impl/FirTypeResolverImpl.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/providers/impl/FirTypeResolverImpl.kt index f50baad3474..9cb6f7df00a 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/providers/impl/FirTypeResolverImpl.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/providers/impl/FirTypeResolverImpl.kt @@ -25,6 +25,7 @@ import org.jetbrains.kotlin.fir.symbols.ConeTypeParameterLookupTag import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol import org.jetbrains.kotlin.fir.symbols.SymbolInternals import org.jetbrains.kotlin.fir.symbols.impl.* +import org.jetbrains.kotlin.fir.symbols.lazyResolveToPhase import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl import org.jetbrains.kotlin.fir.types.impl.ConeTypeParameterTypeImpl @@ -32,6 +33,7 @@ import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintSystemError import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind import org.jetbrains.kotlin.resolve.calls.tower.CandidateApplicability +import org.jetbrains.kotlin.resolve.deprecation.DeprecationInfo import org.jetbrains.kotlin.resolve.deprecation.DeprecationLevelValue import org.jetbrains.kotlin.utils.addToStdlib.shouldNotBeCalled @@ -103,7 +105,13 @@ class FirTypeResolverImpl(private val session: FirSession) : FirTypeResolver() { } if (resolveDeprecations) { - val deprecation = symbol.getDeprecation(session, useSiteFile) + // TODO: drop this condition after KT-57648 + val deprecation = if (symbol is FirClassLikeSymbol<*>) { + symbol.getDeprecation(session, useSiteFile) + } else { + null + } + if (deprecation != null && deprecation.deprecationLevel == DeprecationLevelValue.HIDDEN) { symbolApplicability = minOf(CandidateApplicability.HIDDEN, symbolApplicability) diagnostic = null diff --git a/compiler/testData/diagnostics/tests/EnumEntryAsType.fir.kt b/compiler/testData/diagnostics/tests/EnumEntryAsType.fir.kt index 5600c7ebade..edfdff53079 100644 --- a/compiler/testData/diagnostics/tests/EnumEntryAsType.fir.kt +++ b/compiler/testData/diagnostics/tests/EnumEntryAsType.fir.kt @@ -1,4 +1,3 @@ -// FIR_DISABLE_LAZY_RESOLVE_CHECKS // !DIAGNOSTICS: -UNUSED_PARAMETER enum class Color { diff --git a/compiler/testData/diagnostics/tests/EnumEntryAsType.kt b/compiler/testData/diagnostics/tests/EnumEntryAsType.kt index aeef57ea43b..eafd23d7bc7 100644 --- a/compiler/testData/diagnostics/tests/EnumEntryAsType.kt +++ b/compiler/testData/diagnostics/tests/EnumEntryAsType.kt @@ -1,4 +1,3 @@ -// FIR_DISABLE_LAZY_RESOLVE_CHECKS // !DIAGNOSTICS: -UNUSED_PARAMETER enum class Color { diff --git a/compiler/testData/diagnostics/tests/enum/inheritFromEnumEntry.kt b/compiler/testData/diagnostics/tests/enum/inheritFromEnumEntry.kt index f1645a26064..ccbdeae2112 100644 --- a/compiler/testData/diagnostics/tests/enum/inheritFromEnumEntry.kt +++ b/compiler/testData/diagnostics/tests/enum/inheritFromEnumEntry.kt @@ -1,4 +1,3 @@ -// FIR_DISABLE_LAZY_RESOLVE_CHECKS // FIR_IDENTICAL enum class E { ENTRY