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
@@ -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("")
}