3269a7e693
Function references are now equal if they refer to the same function, and if the parameter/return type adaptation, which happens when a reference is used where some function type is expected, is exactly the same. This includes the number of expected positional parameters (which can be affected by defaults/varargs), whether the coercion of vararg parameter to Array type happened, and whether the coercion of return type to Unit happened. #KT-37543 Fixed
34 lines
885 B
Kotlin
Vendored
34 lines
885 B
Kotlin
Vendored
// TARGET_BACKEND: JVM
|
|
// Temporarily ignored for JVM until KT-36024 is fixed.
|
|
// IGNORE_BACKEND: JVM
|
|
// IGNORE_BACKEND_FIR: JVM_IR
|
|
// WITH_REFLECT
|
|
|
|
import kotlin.reflect.*
|
|
import kotlin.test.assertNotEquals
|
|
|
|
class A {
|
|
fun foo(s: String = "", vararg xs: Long): String = "foo"
|
|
}
|
|
|
|
fun checkNotEqual(x: Any, y: Any) {
|
|
assertNotEquals(x, y)
|
|
assertNotEquals(y, x)
|
|
}
|
|
|
|
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 {
|
|
val foo = A::class.members.single { it.name == "foo" }
|
|
|
|
checkNotEqual(coercionToUnit(A::foo), foo)
|
|
checkNotEqual(varargToElement(A::foo), foo)
|
|
checkNotEqual(defaultAndVararg(A::foo), foo)
|
|
checkNotEqual(allOfTheAbove(A::foo), foo)
|
|
|
|
return "OK"
|
|
}
|