FIR: coerce to Unit when a lambda has early returns

^KT-39075 Fixed
This commit is contained in:
Jinseong Jeon
2021-02-05 10:38:45 -08:00
committed by Dmitriy Novozhilov
parent 83e3201677
commit 37a702b962
3 changed files with 26 additions and 11 deletions
@@ -11,7 +11,7 @@ FILE: coercionToUnitWithEarlyReturn.kt
public final fun foo(x: R|() -> kotlin/Unit|): R|kotlin/Unit| {
}
public final fun main(x: R|A?|): R|kotlin/Unit| {
lval lambda: R|() -> kotlin/Unit?| = l@fun <anonymous>(): R|kotlin/Unit?| {
lval lambda: R|() -> kotlin/Unit| = l@fun <anonymous>(): R|kotlin/Unit| {
when () {
==(R|<local>/x|?.{ $subj$.R|kotlin/Any.hashCode|() }, Int(0)) -> {
^@l Unit
@@ -21,5 +21,5 @@ FILE: coercionToUnitWithEarlyReturn.kt
^ R|<local>/x|?.{ $subj$.R|/A.unit|() }
}
<Inapplicable(INAPPLICABLE): /foo>#(R|<local>/lambda|)
R|/foo|(R|<local>/lambda|)
}
@@ -14,6 +14,5 @@ fun main(x: A?) {
x?.unit()
}
// lambda has a type (() -> Unit?)
<!INAPPLICABLE_CANDIDATE{LT}!><!INAPPLICABLE_CANDIDATE{PSI}!>foo<!>(lambda)<!>
foo(lambda)
}