diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirFunctionReturnTypeMismatchChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirFunctionReturnTypeMismatchChecker.kt index b0e57552c69..1d24280f113 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirFunctionReturnTypeMismatchChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirFunctionReturnTypeMismatchChecker.kt @@ -86,6 +86,16 @@ object FirFunctionReturnTypeMismatchChecker : FirReturnExpressionChecker() { ) } } + } else if (resultExpression.source?.kind == KtFakeSourceElementKind.ImplicitUnit && !functionReturnType.isUnit) { + reporter.reportOn( + resultExpression.source, + RETURN_TYPE_MISMATCH, + functionReturnType, + returnExpressionType, + targetElement, + false, + context + ) } } } diff --git a/compiler/testData/diagnostics/tests/FunctionReturnTypes.fir.kt b/compiler/testData/diagnostics/tests/FunctionReturnTypes.fir.kt index b02fe89bd5b..bc08f5224ee 100644 --- a/compiler/testData/diagnostics/tests/FunctionReturnTypes.fir.kt +++ b/compiler/testData/diagnostics/tests/FunctionReturnTypes.fir.kt @@ -7,9 +7,9 @@ fun unitEmpty() : Unit {} fun unitEmptyReturn() : Unit {return} fun unitIntReturn() : Unit {return 1} fun unitUnitReturn() : Unit {return Unit} -fun test1() : Any = {return} +fun test1() : Any = {return} fun test2() : Any = a@ {return@a 1} -fun test3() : Any { return } +fun test3() : Any { return } fun test4(): ()-> Unit = { return@test4 } fun test5(): Any = l@{ return@l } fun test6(): Any = {return 1} diff --git a/compiler/testData/diagnostics/tests/funReturnsAny.fir.kt b/compiler/testData/diagnostics/tests/funReturnsAny.fir.kt deleted file mode 100644 index c7a4f40b69e..00000000000 --- a/compiler/testData/diagnostics/tests/funReturnsAny.fir.kt +++ /dev/null @@ -1,5 +0,0 @@ -// ISSUE: KT-58460 - -fun someFunction() : Any { - return -} diff --git a/compiler/testData/diagnostics/tests/funReturnsAny.kt b/compiler/testData/diagnostics/tests/funReturnsAny.kt index b2637b69330..b8b0c0be98c 100644 --- a/compiler/testData/diagnostics/tests/funReturnsAny.kt +++ b/compiler/testData/diagnostics/tests/funReturnsAny.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // ISSUE: KT-58460 fun someFunction() : Any {