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
23 lines
625 B
Kotlin
Vendored
23 lines
625 B
Kotlin
Vendored
// IGNORE_BACKEND: JVM_IR, JS, JS_IR, NATIVE
|
|
// IGNORE_BACKEND_FIR: JVM_IR
|
|
// FILE: test.kt
|
|
|
|
fun checkEqual(x: Any, y: Any) {
|
|
if (x != y || y != x) throw AssertionError("$x and $y should be equal")
|
|
if (x.hashCode() != y.hashCode()) throw AssertionError("$x and $y should have the same hash code")
|
|
}
|
|
|
|
fun target(x: Int = 0, vararg ys: String) {}
|
|
|
|
fun captureAll1(fn: () -> Unit): Any = fn
|
|
fun captureAll2(fn: () -> Unit): Any = fn
|
|
|
|
fun box(): String {
|
|
checkEqual(captureAll1(::target), captureAll2(::target))
|
|
return "OK"
|
|
}
|
|
|
|
// FILE: fromOtherFile.kt
|
|
|
|
fun captureAllFromOtherFile(): Any = captureAll1(::target)
|