FIR: fix return statement generation for Unit-returning lambdas...

for case then the expected return type is not Unit.
#KT-56747 fixed
This commit is contained in:
Ilya Chernikov
2023-03-20 11:59:23 +01:00
committed by Space Team
parent 505edb9746
commit aa3c189d83
5 changed files with 8 additions and 4 deletions
@@ -65,7 +65,7 @@ fun FirAnonymousFunction.addReturnToLastStatementIfNeeded() {
if (lastStatement is FirReturnExpression) return
val returnType = (body.typeRef as? FirResolvedTypeRef) ?: return
if (returnType.isNothing || returnType.isUnit) return
if (returnType.isNothing) return
val returnTarget = FirFunctionTarget(null, isLambda = isLambda).also { it.bind(this) }
val returnExpression = buildReturnExpression {
@@ -43,7 +43,11 @@ suspend fun box() {
// test.kt:16 box: $continuation:kotlin.coroutines.Continuation=TestKt$box$1, $result:java.lang.Object=null, $i$f$suspendBar:int=0:int, $this$extensionFun$iv$iv:AtomicInt=AtomicInt, $i$f$extensionFun:int=0:int
// test.kt:20 box: $continuation:kotlin.coroutines.Continuation=TestKt$box$1, $result:java.lang.Object=null, $i$f$suspendBar:int=0:int
// test.kt:21 box: $continuation:kotlin.coroutines.Continuation=TestKt$box$1, $result:java.lang.Object=null, $i$f$suspendBar:int=0:int, $i$a$-suspendCoroutineUninterceptedOrReturn-TestKt$suspendBar$2$iv:int=0:int
// EXPECTATIONS ClassicFrontend JVM JVM_IR
// test.kt:22 box: $continuation:kotlin.coroutines.Continuation=TestKt$box$1, $result:java.lang.Object=null, $i$f$suspendBar:int=0:int, $i$a$-suspendCoroutineUninterceptedOrReturn-TestKt$suspendBar$2$iv:int=0:int
// EXPECTATIONS ClassicFrontend FIR JVM JVM_IR
// test.kt:20 box: $continuation:kotlin.coroutines.Continuation=TestKt$box$1, $result:java.lang.Object=null, $i$f$suspendBar:int=0:int
// test.kt:23 box: $continuation:kotlin.coroutines.Continuation=TestKt$box$1, $result:java.lang.Object=null, $i$f$suspendBar:int=0:int
// test.kt:26 box: $continuation:kotlin.coroutines.Continuation=TestKt$box$1, $result:java.lang.Object=null
@@ -11,4 +11,5 @@ FILE fqName:<root> fileName:/lambdaReturningUnit.kt
block: FUN_EXPR type=kotlin.Function0<kotlin.Any?> origin=LAMBDA
FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> () returnType:kotlin.Any?
BLOCK_BODY
GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit
RETURN type=kotlin.Nothing from='local final fun <anonymous> (): kotlin.Any? declared in <root>.box'
GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit
@@ -4,7 +4,7 @@ inline fun flaf(block: Function0<Any?>) {
suspend fun box() {
flaf(block = local fun <anonymous>(): Any? {
Unit
return Unit
}
)
}
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_K2: JS_IR
// EXPECTED_REACHABLE_NODES: 1285
fun <T> rawReturnValue(fn: () -> T): Any {