Do not force coercion to Unit for nullable lambda return type
#KT-41005 Fixed
This commit is contained in:
Vendored
+22
@@ -0,0 +1,22 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
// FILE: TestJ.java
|
||||
|
||||
public class TestJ {
|
||||
public static <T> In<T> materialize() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
class In<in T>
|
||||
|
||||
fun <T> inferred(e: In<T>?, l: () -> T): T = l()
|
||||
|
||||
fun box(): String {
|
||||
// coercion to Unit for T!
|
||||
val inferred = (inferred(TestJ.materialize<Unit>(), { null })).toString()
|
||||
return if (inferred == "kotlin.Unit") "OK" else "fail : $inferred"
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
fun <T> nullableK(m: () -> T?) = m()
|
||||
|
||||
fun box(): String {
|
||||
// no coercion to Unit for T?
|
||||
val nullableK = (nullableK<Unit> { null }).toString()
|
||||
return if (nullableK == "null") "OK" else "fail: $nullableK"
|
||||
}
|
||||
Reference in New Issue
Block a user