@OverloadResolutionByLambdaReturnType
fun foo(cb: (Unit) -> String) = Unit // (1)
@OverloadResolutionByLambdaReturnType
fun foo(cb: (Unit) -> CharSequence) = Unit // (2)
fun testError02() {
// Error: required String, found CharSequence
foo { a ->
val a: CharSequence = "42"
a
}
// Both (1) and (2) are applicable
// (1) is the only most specific candidate
// We do not attempt refinement by the lambda return type
}
Seems that the current limitation is intended. Probably the compiler would be too complex otherwise.