K2: change resolution for deprecated actual declaration

This commit addresses a scenario where an 'actual' declaration is marked
with a Deprecated annotation at the 'Hidden' level, while the
corresponding 'expect' declaration is not. When resolving,
'CheckHiddenDeclaration' marks the 'actual' declaration as unsuccessful,
leading to the selection of the 'expect' declaration as the successful
candidate.

'FirDeprecationChecker' handles a case where an 'actual' class is
annotated with Deprecated, but the 'expect' class is not. During the
checking of the 'actual' class constructor, 'CheckHiddenDeclaration'
skips it due to the absence of a direct Deprecated annotation.
'FirDeprecationChecker' then identifies this constructor and reports a
DEPRECATION_ERROR.

'FirDeprecationChecker' will now be applied to solving problems related
to 'actual' declarations with corresponding Deprecated annotations. The
process remains the same: 'CheckHiddenDeclaration' will skip the
'actual' declaration, and then 'FirDeprecationChecker' will identify it
and report the error.

^KT-61792 Fixed
This commit is contained in:
Anastasia.Nekrasova
2023-12-13 13:26:51 +02:00
committed by Space Team
parent 2cdf8cd7b1
commit e58b5e7d22
8 changed files with 147 additions and 4 deletions
@@ -25540,6 +25540,22 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
}
}
@Nested
@TestMetadata("compiler/testData/diagnostics/tests/multiplatform/deprecatedAnnotation")
@TestDataPath("$PROJECT_ROOT")
public class DeprecatedAnnotation {
@Test
public void testAllFilesPresentInDeprecatedAnnotation() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/multiplatform/deprecatedAnnotation"), Pattern.compile("^(.+)\\.(kt|kts)$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true);
}
@Test
@TestMetadata("hidden.kt")
public void testHidden() throws Exception {
runTest("compiler/testData/diagnostics/tests/multiplatform/deprecatedAnnotation/hidden.kt");
}
}
@Nested
@TestMetadata("compiler/testData/diagnostics/tests/multiplatform/enum")
@TestDataPath("$PROJECT_ROOT")
@@ -25540,6 +25540,22 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
}
}
@Nested
@TestMetadata("compiler/testData/diagnostics/tests/multiplatform/deprecatedAnnotation")
@TestDataPath("$PROJECT_ROOT")
public class DeprecatedAnnotation {
@Test
public void testAllFilesPresentInDeprecatedAnnotation() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/multiplatform/deprecatedAnnotation"), Pattern.compile("^(.+)\\.(kt|kts)$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true);
}
@Test
@TestMetadata("hidden.kt")
public void testHidden() throws Exception {
runTest("compiler/testData/diagnostics/tests/multiplatform/deprecatedAnnotation/hidden.kt");
}
}
@Nested
@TestMetadata("compiler/testData/diagnostics/tests/multiplatform/enum")
@TestDataPath("$PROJECT_ROOT")
@@ -1387,6 +1387,22 @@ public class FirOldFrontendMPPDiagnosticsWithLightTreeTestGenerated extends Abst
}
}
@Nested
@TestMetadata("compiler/testData/diagnostics/tests/multiplatform/deprecatedAnnotation")
@TestDataPath("$PROJECT_ROOT")
public class DeprecatedAnnotation {
@Test
public void testAllFilesPresentInDeprecatedAnnotation() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/multiplatform/deprecatedAnnotation"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), TargetBackend.JVM_IR, true);
}
@Test
@TestMetadata("hidden.kt")
public void testHidden() throws Exception {
runTest("compiler/testData/diagnostics/tests/multiplatform/deprecatedAnnotation/hidden.kt");
}
}
@Nested
@TestMetadata("compiler/testData/diagnostics/tests/multiplatform/enum")
@TestDataPath("$PROJECT_ROOT")
@@ -1387,6 +1387,22 @@ public class FirOldFrontendMPPDiagnosticsWithPsiTestGenerated extends AbstractFi
}
}
@Nested
@TestMetadata("compiler/testData/diagnostics/tests/multiplatform/deprecatedAnnotation")
@TestDataPath("$PROJECT_ROOT")
public class DeprecatedAnnotation {
@Test
public void testAllFilesPresentInDeprecatedAnnotation() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/multiplatform/deprecatedAnnotation"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), TargetBackend.JVM_IR, true);
}
@Test
@TestMetadata("hidden.kt")
public void testHidden() throws Exception {
runTest("compiler/testData/diagnostics/tests/multiplatform/deprecatedAnnotation/hidden.kt");
}
}
@Nested
@TestMetadata("compiler/testData/diagnostics/tests/multiplatform/enum")
@TestDataPath("$PROJECT_ROOT")
@@ -9,10 +9,7 @@ import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.fir.FirElement
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.declarations.utils.isFun
import org.jetbrains.kotlin.fir.declarations.utils.isInfix
import org.jetbrains.kotlin.fir.declarations.utils.isOperator
import org.jetbrains.kotlin.fir.declarations.utils.modality
import org.jetbrains.kotlin.fir.declarations.utils.*
import org.jetbrains.kotlin.fir.expressions.*
import org.jetbrains.kotlin.fir.languageVersionSettings
import org.jetbrains.kotlin.fir.matchingParameterFunctionType
@@ -760,6 +757,8 @@ internal object CheckCallModifiers : CheckerStage() {
internal object CheckHiddenDeclaration : ResolutionStage() {
override suspend fun check(candidate: Candidate, callInfo: CallInfo, sink: CheckerSink, context: ResolutionContext) {
val symbol = candidate.symbol as? FirCallableSymbol<*> ?: return
/** Actual declarations are checked by [FirDeprecationChecker] */
if (symbol.isActual) return
val deprecation = symbol.getDeprecation(context.session, callInfo.callSite)
if (deprecation?.deprecationLevel == DeprecationLevelValue.HIDDEN || isHiddenForThisCallSite(symbol, callInfo, candidate)) {
sink.yieldDiagnostic(HiddenCandidate)
@@ -0,0 +1,32 @@
// MODULE: m1-common
// FILE: common.kt
expect class A()
expect class B()
expect fun foo(test: String)
fun test() {
A()
B()
foo("")
}
// MODULE: m2-jvm()()(m1-common)
// FILE: jvm.kt
@Deprecated("", level = DeprecationLevel.HIDDEN)
actual class A
actual class B @Deprecated("", level = DeprecationLevel.HIDDEN) actual constructor(){}
@Deprecated("", level = DeprecationLevel.HIDDEN)
actual fun foo(test: String) {
}
fun main() {
<!DEPRECATION_ERROR!>A<!>()
<!DEPRECATION_ERROR!>B<!>()
<!DEPRECATION_ERROR!>foo<!>("")
}
@@ -0,0 +1,32 @@
// MODULE: m1-common
// FILE: common.kt
expect class A()
expect class B()
expect fun foo(test: String)
fun test() {
<!DEPRECATION_ERROR{JVM}!>A<!>()
<!UNRESOLVED_REFERENCE{JVM}!>B<!>()
foo("")
}
// MODULE: m2-jvm()()(m1-common)
// FILE: jvm.kt
@Deprecated("", level = DeprecationLevel.HIDDEN)
actual class A
actual class B @Deprecated("", level = DeprecationLevel.HIDDEN) actual constructor(){}
@Deprecated("", level = DeprecationLevel.HIDDEN)
actual fun foo(test: String) {
}
fun main() {
<!DEPRECATION_ERROR!>A<!>()
<!UNRESOLVED_REFERENCE!>B<!>()
foo("")
}
@@ -25540,6 +25540,22 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
}
}
@Nested
@TestMetadata("compiler/testData/diagnostics/tests/multiplatform/deprecatedAnnotation")
@TestDataPath("$PROJECT_ROOT")
public class DeprecatedAnnotation {
@Test
public void testAllFilesPresentInDeprecatedAnnotation() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/multiplatform/deprecatedAnnotation"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true);
}
@Test
@TestMetadata("hidden.kt")
public void testHidden() throws Exception {
runTest("compiler/testData/diagnostics/tests/multiplatform/deprecatedAnnotation/hidden.kt");
}
}
@Nested
@TestMetadata("compiler/testData/diagnostics/tests/multiplatform/enum")
@TestDataPath("$PROJECT_ROOT")