diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/BranchedFoldingUtils.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/BranchedFoldingUtils.kt index cd2be440eb7..aa84f5a5e39 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/BranchedFoldingUtils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/BranchedFoldingUtils.kt @@ -43,7 +43,9 @@ object BranchedFoldingUtils { } fun getFoldableBranchedReturn(branch: KtExpression?): KtReturnExpression? = - (branch?.lastBlockStatementOrThis() as? KtReturnExpression)?.takeIf { it.returnedExpression != null } + (branch?.lastBlockStatementOrThis() as? KtReturnExpression)?.takeIf { + it.returnedExpression != null && it.returnedExpression !is KtLambdaExpression + } fun checkAssignmentsMatch(a1: KtBinaryExpression, a2: KtBinaryExpression): Boolean = a1.left?.text == a2.left?.text && a1.operationToken == a2.operationToken diff --git a/idea/testData/inspectionsLocal/liftOut/whenToReturn/whenWithLambda.kt b/idea/testData/inspectionsLocal/liftOut/whenToReturn/whenWithLambda.kt new file mode 100644 index 00000000000..0c250a50129 --- /dev/null +++ b/idea/testData/inspectionsLocal/liftOut/whenToReturn/whenWithLambda.kt @@ -0,0 +1,8 @@ +// PROBLEM: none + +fun foo(x: Boolean): (Int) -> String { + when (x) { + true -> return { it.toString() } + else -> return { "42" } + } +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java index 872d6634047..d23148298a5 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java @@ -648,6 +648,12 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/liftOut/whenToReturn/whenThrowOnly.kt"); doTest(fileName); } + + @TestMetadata("whenWithLambda.kt") + public void testWhenWithLambda() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/liftOut/whenToReturn/whenWithLambda.kt"); + doTest(fileName); + } } }