K2 opt-in: don't take sub./int. override parent classes into account

#KT-54823 Fixed
This commit is contained in:
Mikhail Glukhikh
2022-11-15 13:14:16 +01:00
committed by Space Team
parent c1c5933c72
commit 73cb4d1a6e
7 changed files with 109 additions and 9 deletions
@@ -0,0 +1,31 @@
// FIR_IDENTICAL
// See KT-54823
@RequiresOptIn
annotation class Marker
interface VeryBase<T> {
fun foo(base: VeryBase<*>) {}
}
@Marker
abstract class Base<T> : VeryBase<T> {
fun bar(base: Base<*>) {}
fun baz() {}
}
@OptIn(Marker::class)
open class Intermediate : Base<String>()
class Derived : Intermediate()
fun main() {
val d = Derived()
// Should be Ok (declared in VeryBase without marker)
d.foo(d)
// Should be Ok (declared in Base with marker, but called on a receiver of type Derived without marker)
d.baz()
// Should be Error (has a parameter of type Base with marker)
d.<!OPT_IN_USAGE_ERROR!>bar<!>(d)
}