Remove error on annotated types as arguments to typeOf
Instead, document that `KType.annotations` returns an empty list for types created with `typeOf`. Annotations might be supported in the future. #KT-49573 Fixed #KT-29919
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.*
|
||||
|
||||
@Target(AnnotationTarget.TYPE)
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class Runtime
|
||||
|
||||
@Target(AnnotationTarget.TYPE)
|
||||
@Retention(AnnotationRetention.BINARY)
|
||||
annotation class Binary
|
||||
|
||||
@Target(AnnotationTarget.TYPE)
|
||||
@Retention(AnnotationRetention.SOURCE)
|
||||
annotation class Source
|
||||
|
||||
inline fun <reified X> f() = g<List<X>>()
|
||||
inline fun <reified Y> g() = typeOf<Y>()
|
||||
|
||||
inline fun <reified Z> a() = typeOf<@Runtime Z>()
|
||||
|
||||
inline fun <reified R> test() {
|
||||
check(typeOf<@Runtime R.() -> Unit>())
|
||||
check(typeOf<R.() -> Unit>())
|
||||
}
|
||||
|
||||
fun check(type: KType) {
|
||||
if (type.annotations.isNotEmpty()) {
|
||||
error("KType.annotations should be empty: ${type.annotations}")
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
check(typeOf<String.() -> Int>())
|
||||
check(f<Int.(Int) -> Unit>())
|
||||
|
||||
check(typeOf<@Runtime Int.() -> List<String>>())
|
||||
check(f<@Runtime Unit.() -> Array<*>>())
|
||||
|
||||
check(typeOf<@Runtime String>())
|
||||
check(f<@Runtime String>())
|
||||
check(typeOf<@Binary String>())
|
||||
check(f<@Binary String>())
|
||||
check(typeOf<@Source String>())
|
||||
check(f<@Source String>())
|
||||
|
||||
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
check(typeOf<@kotlin.internal.Exact String>())
|
||||
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
check(f<@kotlin.internal.Exact String>())
|
||||
|
||||
check(typeOf<Map<String, List<@Runtime Int>>>())
|
||||
check(f<Map<String, List<@Runtime Int>>>())
|
||||
|
||||
check(a<String>())
|
||||
|
||||
test<String>()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.reflect.*
|
||||
|
||||
@Target(AnnotationTarget.TYPE)
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class Runtime
|
||||
|
||||
@Target(AnnotationTarget.TYPE)
|
||||
@Retention(AnnotationRetention.BINARY)
|
||||
annotation class Binary
|
||||
|
||||
@Target(AnnotationTarget.TYPE)
|
||||
@Retention(AnnotationRetention.SOURCE)
|
||||
annotation class Source
|
||||
|
||||
inline fun <reified X> f() = g<List<X>>()
|
||||
inline fun <reified Y> g() = typeOf<Y>()
|
||||
|
||||
inline fun <reified Z> a() = typeOf<@Runtime Z>()
|
||||
|
||||
inline fun <reified R> test() {
|
||||
check(typeOf<@Runtime R.() -> Unit>())
|
||||
check(typeOf<R.() -> Unit>())
|
||||
}
|
||||
|
||||
fun check(type: KType) {
|
||||
if (type.annotations.isNotEmpty()) {
|
||||
error("KType.annotations should be empty: ${type.annotations}")
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
check(typeOf<String.() -> Int>())
|
||||
check(f<Int.(Int) -> Unit>())
|
||||
|
||||
check(typeOf<@Runtime Int.() -> List<String>>())
|
||||
check(f<@Runtime Unit.() -> Array<*>>())
|
||||
|
||||
check(typeOf<@Runtime String>())
|
||||
check(f<@Runtime String>())
|
||||
check(typeOf<@Binary String>())
|
||||
check(f<@Binary String>())
|
||||
check(typeOf<@Source String>())
|
||||
check(f<@Source String>())
|
||||
|
||||
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
check(typeOf<@kotlin.internal.Exact String>())
|
||||
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
check(f<@kotlin.internal.Exact String>())
|
||||
|
||||
check(typeOf<Map<String, List<@Runtime Int>>>())
|
||||
check(f<Map<String, List<@Runtime Int>>>())
|
||||
|
||||
check(a<String>())
|
||||
|
||||
test<String>()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user