Files
kotlin-fork/compiler/testData/codegen/box/annotations/annotatedLambda/samFunReference.kt
T
Mikhail Zarechenskiy 8bdc4d34f7 [NI] Commonize type-conversions (SAM/Suspend)
- Allow participating subtypes of functional types in conversions
 - Fix several subtle inconsistencies
 - Place logic about conversions at one place

 Now conversions operations have two stages: before usual subtyping
 check and after one. This is needed to support conversions of
 subtypes (of functional types, for example). First, the compiler
 checks if it possible to resolve an argument without conversion and
 only then it tries to perform conversion.
 Note that it'd be incorrect to perform conversion eagerly as it can
 change resolve (Runnable & () -> Unit <: KRunnable), plus we can't
 guess whether conversion is needed at all as it's important not to
 look into supertypes if resolution doesn't actually needed it

 #KT-36448 Fixed
 #KT-37574 Fixed
 #KT-38604 Fixed
2020-05-20 15:30:14 +03:00

56 lines
1.4 KiB
Kotlin
Vendored

// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// FILE: Test.java
class Test {
public static Class<?> apply(Runnable x) {
return x.getClass();
}
public static interface ABC {
void apply(String x1, String x2);
}
public static Class<?> applyABC(ABC x) {
return x.getClass();
}
}
// FILE: test.kt
import java.lang.reflect.Method
import kotlin.test.assertEquals
@Retention(AnnotationRetention.RUNTIME)
annotation class Ann(val x: String)
fun testMethodNoAnnotations(method: Method, name: String) {
assertEquals(0, method.getDeclaredAnnotations().size, "No method annotations expected `$name`")
for ((index, annotations) in method.getParameterAnnotations().withIndex()) {
assertEquals(0, annotations.size, "No parameter $index annotations expected `$name`")
}
}
fun testClass(clazz: Class<*>, name: String) {
val invokes = clazz.getDeclaredMethods().single() { !it.isBridge() }
testMethodNoAnnotations(invokes, name)
}
@Ann("OK")
fun annotatedABC(@Ann("OK0") x: String, @Ann("OK1") y: String) {}
@Ann("OK")
fun annotatedRunnable() {}
fun box(): String {
testClass(Test.applyABC(::annotatedABC), "1")
testClass(Test.apply(::annotatedRunnable), "2")
val abcReference = ::annotatedABC
testClass(Test.applyABC(abcReference), "3")
val runnableReference = ::annotatedRunnable
testClass(Test.apply(runnableReference), "4")
return "OK"
}