diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirFunctionReturnChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirFunctionReturnChecker.kt index 374471da3d3..dbd34b66f7b 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirFunctionReturnChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirFunctionReturnChecker.kt @@ -35,7 +35,7 @@ object FirFunctionReturnChecker : FirFunctionChecker() { if (declaration is FirConstructor) return if (declaration is FirAnonymousFunction && declaration.isLambda) return val returnType = declaration.returnTypeRef.coneType.fullyExpandedType(context.session) - if (returnType.isUnit || returnType.isNothing) return + if (returnType.isUnit) return val graph = declaration.controlFlowGraphReference?.controlFlowGraph ?: return val blockExitNode = graph.exitNode.previousNodes.lastOrNull { it is BlockExitNode } ?: return diff --git a/compiler/testData/diagnostics/tests/FunctionReturnTypes.fir.kt b/compiler/testData/diagnostics/tests/FunctionReturnTypes.fir.kt index bc08f5224ee..783b1ace38d 100644 --- a/compiler/testData/diagnostics/tests/FunctionReturnTypes.fir.kt +++ b/compiler/testData/diagnostics/tests/FunctionReturnTypes.fir.kt @@ -158,6 +158,8 @@ fun illegalReturnIf(): Char { fun returnNothing(): Nothing { throw 1 } +fun returnNothingEmpty(): Nothing { +} fun f(): Int { if (1 < 2) { return 1 } else returnNothing() } diff --git a/compiler/testData/diagnostics/tests/FunctionReturnTypes.kt b/compiler/testData/diagnostics/tests/FunctionReturnTypes.kt index 3b6a8a3cf07..f548c71a02c 100644 --- a/compiler/testData/diagnostics/tests/FunctionReturnTypes.kt +++ b/compiler/testData/diagnostics/tests/FunctionReturnTypes.kt @@ -158,6 +158,8 @@ fun illegalReturnIf(): Char { fun returnNothing(): Nothing { throw 1 } +fun returnNothingEmpty(): Nothing { +} fun f(): Int { if (1 < 2) { return 1 } else returnNothing() } diff --git a/compiler/testData/diagnostics/tests/FunctionReturnTypes.txt b/compiler/testData/diagnostics/tests/FunctionReturnTypes.txt index 5af51a4886b..85499c952d7 100644 --- a/compiler/testData/diagnostics/tests/FunctionReturnTypes.txt +++ b/compiler/testData/diagnostics/tests/FunctionReturnTypes.txt @@ -47,6 +47,7 @@ public fun nonBlockNoReturnIfUnitInOneBranch(): kotlin.Int public fun nonBlockReturnIfEmptyIf(): kotlin.Int public fun none(): kotlin.Unit public fun returnNothing(): kotlin.Nothing +public fun returnNothingEmpty(): kotlin.Nothing public fun test1(): kotlin.Any public fun test2(): kotlin.Any public fun test3(): kotlin.Any