Files
kotlin-fork/compiler/testData/codegen/box/callableReference/equality/varargAsArrayMemberOrExtension.kt
T
Alexander Udalov 3269a7e693 Change behavior of equals/hashCode on adapted function references
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
2020-04-01 14:18:49 +02:00

30 lines
821 B
Kotlin
Vendored

// IGNORE_BACKEND_FIR: JVM_IR
// FILE: test.kt
fun checkNotEqual(x: Any, y: Any) {
if (x == y || y == x) throw AssertionError("$x and $y should NOT be equal")
}
class C {
fun member(vararg xs: String) {}
}
fun C.extension(vararg xs: String) {}
fun capture1(fn: C.(String) -> Unit): Any = fn
fun capture2(fn: C.(Array<String>) -> Unit): Any = fn
fun box(): String {
checkNotEqual(capture1(C::member), capture2(C::member))
checkNotEqual(capture1(C::member), captureMemberFromOtherFile())
checkNotEqual(capture1(C::extension), capture2(C::extension))
checkNotEqual(capture1(C::extension), captureExtensionFromOtherFile())
return "OK"
}
// FILE: fromOtherFile.kt
fun captureMemberFromOtherFile(): Any = capture2(C::member)
fun captureExtensionFromOtherFile(): Any = capture2(C::extension)