Support calling methods annotated with PolymorphicSignature

#KT-14416 Fixed
 #KT-26165 Fixed
This commit is contained in:
Alexander Udalov
2018-11-12 17:38:42 +01:00
parent b940418604
commit a796f11934
18 changed files with 595 additions and 25 deletions
@@ -0,0 +1,37 @@
// !LANGUAGE: +PolymorphicSignature
// TARGET_BACKEND: JVM
// IGNORE_BACKEND: JVM_IR
// FULL_JDK
// SKIP_JDK6
// WITH_RUNTIME
import java.lang.invoke.MethodHandles
import java.lang.invoke.MethodType
import java.lang.invoke.WrongMethodTypeException
interface I {
fun get(): String
}
class C {
fun run(i: I): String = i.get()
}
fun box(): String {
val mh = MethodHandles.lookup().findVirtual(
C::class.java, "run",
MethodType.methodType(String::class.java, I::class.java)
)
try {
return mh.invokeExact(C(), object : I {
override fun get(): String = "Fail"
}) as String
} catch (e: WrongMethodTypeException) {
// OK
}
return mh.invoke(C(), object : I {
override fun get(): String = "OK"
}) as String
}