b7a7fce34e
For non-suspend lambdas annotations are carried over to the invoke method so that tooling can find the annotation there. It seems reasonable that annotations are carried over to the invokeSuspend method on suspend lambdas as well so that similar tooling can be built and work for suspend lambdas.
33 lines
923 B
Kotlin
Vendored
33 lines
923 B
Kotlin
Vendored
// TARGET_BACKEND: JVM
|
|
|
|
// WITH_STDLIB
|
|
|
|
import java.lang.reflect.Method
|
|
import kotlin.test.assertEquals
|
|
|
|
@Target(AnnotationTarget.FUNCTION)
|
|
@Retention(AnnotationRetention.RUNTIME)
|
|
annotation class Ann(val x: String)
|
|
|
|
fun foo0(block: () -> Unit) = block.javaClass
|
|
|
|
fun testMethod(method: Method, name: String) {
|
|
assertEquals("OK", method.getAnnotation(Ann::class.java).x, "On method of test named `$name`")
|
|
|
|
for ((index, annotations) in method.getParameterAnnotations().withIndex()) {
|
|
val ann = annotations.filterIsInstance<Ann>().single()
|
|
assertEquals("OK$index", ann.x, "On parameter $index of test named `$name`")
|
|
}
|
|
}
|
|
|
|
fun testClass(clazz: Class<*>, name: String) {
|
|
val invokes = clazz.getDeclaredMethods().single() { !it.isBridge() }
|
|
testMethod(invokes, name)
|
|
}
|
|
|
|
fun box(): String {
|
|
testClass(foo0(@Ann("OK") { }), "1")
|
|
testClass(foo0() @Ann("OK") { }, "2")
|
|
return "OK"
|
|
}
|