[FIR] Infer Unit type for generic lambda function if implicit return exists

Make behavior more consistent with K1

^KT-63563 Fixed
This commit is contained in:
Ivan Kochurkin
2023-12-19 20:57:21 +01:00
committed by Space Team
parent b19c496c44
commit a2cd2200d6
12 changed files with 57 additions and 47 deletions
@@ -0,0 +1,22 @@
// FIR_IDENTICAL
// ISSUE: KT-63563
fun foo(x: () -> Any) = x()
fun foo2(x: () -> Unit) = x()
fun <T> foo3(x: () -> T): T = x()
fun main2() {
foo {
if ("0".hashCode() == 42) <!RETURN_TYPE_MISMATCH!>return@foo<!>
""
}
foo2 {
if ("1".hashCode() == 42) return@foo2
""
}
foo3 { // Infer T to Unit -> no error
if ("2".hashCode() == 42) return@foo3
""
}
}
@@ -1,6 +0,0 @@
fun test(a: Int) {
run f@{
if (a > 0) <!RETURN_TYPE_MISMATCH!>return@f<!>
else return@f 1
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
fun test(a: Int) {
run f@{
if (a > 0) return@f
@@ -1,20 +0,0 @@
// NI_EXPECTED_FILE
val flag = true
// type of a was checked by txt
val a = run { // () -> Unit
return@run
}
// Unit
val b = run {
if (flag) return@run
5
}
// Unit
val c = run {
if (flag) <!RETURN_TYPE_MISMATCH!>return@run<!>
return@run 4
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// NI_EXPECTED_FILE
val flag = true