Files
kotlin-fork/compiler/testData/diagnostics/tests/callableReference/function/ambiguityTopLevelVsTopLevelGeneric.kt
T
Mikhail Glukhikh 2680c8effd K2: allow/disallow coercion-to-unit for callable references more precisely
Before this commit, K2 always applied coercion-to-unit for
callable references if expected type was Unit, and actual non-Unit.
However, this may not work in case when actual return type is
a type parameter and it must be inferred into Unit.
In this commit we started to disallow coercion-to-unit
for references with synthetic outer call (~ top-level in K1)
AND a type parameter as a return type (both should be true to disallow).
This provides better K1 consistency,
while still keeping some broken K1 cases working in K2.

See also added comment in CallableReferenceResolution.kt.

#KT-62565 Fixed
2023-12-12 13:52:29 +00:00

9 lines
249 B
Kotlin
Vendored

fun foo(x: Int, y: Any): Int = x
fun <T> bar(x: T, y: Any): T = x
fun main() {
val fooRef: (Int, Any) -> Unit = <!TYPE_MISMATCH!>::<!TYPE_MISMATCH!>foo<!><!>
val barRef: (Int, Any) -> Unit = <!TYPE_MISMATCH!>::<!TYPE_MISMATCH!>bar<!><!>
}