Support toString for AdaptedFunctionReference subclasses
Also make it serializable like other lambdas, suspend lambdas and normal callable references.
This commit is contained in:
+27
@@ -0,0 +1,27 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class A {
|
||||
fun foo(s: String = "", vararg xs: Long): CharSequence = "foo"
|
||||
}
|
||||
|
||||
fun check(expected: String, x: Any) {
|
||||
assertEquals(expected, x.toString())
|
||||
}
|
||||
|
||||
fun coercionToUnit(f: (A, String, LongArray) -> Unit): Any = f
|
||||
fun varargToElement(f: (A, String, Long, Long) -> CharSequence): Any = f
|
||||
fun defaultAndVararg(f: (A) -> CharSequence): Any = f
|
||||
fun allOfTheAbove(f: (A) -> Unit): Any = f
|
||||
|
||||
fun box(): String {
|
||||
check("Function3<A, java.lang.String, long[], kotlin.Unit>", coercionToUnit(A::foo))
|
||||
check("Function4<A, java.lang.String, java.lang.Long, java.lang.Long, java.lang.CharSequence>", varargToElement(A::foo))
|
||||
check("Function1<A, java.lang.CharSequence>", defaultAndVararg(A::foo))
|
||||
check("Function1<A, kotlin.Unit>", allOfTheAbove(A::foo))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// WITH_REFLECT
|
||||
|
||||
import java.io.*
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class A {
|
||||
fun foo(s: String = "", vararg xs: Long): String = "foo"
|
||||
}
|
||||
|
||||
fun check(x: Any) {
|
||||
val baos = ByteArrayOutputStream()
|
||||
val oos = ObjectOutputStream(baos)
|
||||
oos.writeObject(x)
|
||||
oos.close()
|
||||
|
||||
val bais = ByteArrayInputStream(baos.toByteArray())
|
||||
val ois = ObjectInputStream(bais)
|
||||
assertEquals(x, ois.readObject())
|
||||
ois.close()
|
||||
}
|
||||
|
||||
fun coercionToUnit(f: (A, String, LongArray) -> Unit): Any = f
|
||||
fun varargToElement(f: (A, String, Long, Long) -> String): Any = f
|
||||
fun defaultAndVararg(f: (A) -> String): Any = f
|
||||
fun allOfTheAbove(f: (A) -> Unit): Any = f
|
||||
|
||||
fun box(): String {
|
||||
check(coercionToUnit(A::foo))
|
||||
check(varargToElement(A::foo))
|
||||
check(defaultAndVararg(A::foo))
|
||||
check(allOfTheAbove(A::foo))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user