Report EXPERIMENTAL_API diagnostics on various implicit usages
#KT-32443 Fixed #KT-22852 Fixed
This commit is contained in:
committed by
teamcityserver
parent
d8d38862d9
commit
0a670bf055
+113
@@ -0,0 +1,113 @@
|
||||
// !USE_EXPERIMENTAL: kotlin.RequiresOptIn
|
||||
|
||||
@RequiresOptIn
|
||||
@Retention(AnnotationRetention.BINARY)
|
||||
annotation class Marker
|
||||
|
||||
@Marker
|
||||
interface Some
|
||||
|
||||
abstract class User {
|
||||
abstract fun createSome(): Some
|
||||
fun Some?.onSome() {}
|
||||
fun withSome(some: Some? = null) {}
|
||||
|
||||
fun use() {
|
||||
val something = createSome()
|
||||
val somethingOther: Some = createSome()
|
||||
null.onSome()
|
||||
withSome()
|
||||
}
|
||||
}
|
||||
|
||||
data class DataClass(@property:Marker val x: Int)
|
||||
|
||||
fun useDataClass(d: DataClass) {
|
||||
// Should have error in both
|
||||
d.x
|
||||
val (x) = d
|
||||
}
|
||||
|
||||
typealias My = Some
|
||||
|
||||
fun my(my: My) {}
|
||||
|
||||
fun your(my: Some) {}
|
||||
|
||||
@Marker
|
||||
interface ExperimentalType {
|
||||
fun foo() {}
|
||||
fun bar() {}
|
||||
}
|
||||
|
||||
@OptIn(Marker::class)
|
||||
interface NotExperimentalExtension : ExperimentalType {
|
||||
override fun foo() {}
|
||||
}
|
||||
|
||||
fun use(arg: NotExperimentalExtension) {
|
||||
arg.foo()
|
||||
arg.bar()
|
||||
}
|
||||
|
||||
@Marker
|
||||
interface I
|
||||
|
||||
@OptIn(Marker::class)
|
||||
class A : I
|
||||
|
||||
@OptIn(Marker::class)
|
||||
class B : I
|
||||
|
||||
fun main() {
|
||||
val x = listOf(A(), B())
|
||||
}
|
||||
|
||||
@Marker
|
||||
class C {
|
||||
operator fun getValue(x: Any?, y: Any?): String = ""
|
||||
}
|
||||
|
||||
object O {
|
||||
@OptIn(Marker::class)
|
||||
operator fun provideDelegate(x: Any?, y: Any?): C = C()
|
||||
}
|
||||
|
||||
val x: String by O
|
||||
|
||||
@Marker
|
||||
class OperatorContainer : Comparable<OperatorContainer> {
|
||||
@OptIn(Marker::class)
|
||||
override fun compareTo(other: OperatorContainer): Int {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(Marker::class)
|
||||
class AnotherContainer : Iterable<C> {
|
||||
@OptIn(Marker::class)
|
||||
override fun iterator(): Iterator<C> {
|
||||
return object : Iterator<C> {
|
||||
override fun hasNext(): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
override fun next(): C {
|
||||
throw java.util.NoSuchElementException()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(Marker::class)
|
||||
operator fun String.minus(s: String) = OperatorContainer()
|
||||
|
||||
@OptIn(Marker::class)
|
||||
operator fun String.invoke() = OperatorContainer()
|
||||
|
||||
fun operatorContainerUsage(s: String, a: AnotherContainer) {
|
||||
val res1 = s - s
|
||||
val res2 = s()
|
||||
val res3 = res1 > res2
|
||||
for (c in a) {}
|
||||
}
|
||||
Reference in New Issue
Block a user