Lift return out: do not suggest for lambda in return #KT-18711 Fixed

This commit is contained in:
Mikhail Glukhikh
2017-07-05 15:23:27 +03:00
parent c0d10264bc
commit 9c4dfa3343
3 changed files with 17 additions and 1 deletions
@@ -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
@@ -0,0 +1,8 @@
// PROBLEM: none
fun foo(x: Boolean): (Int) -> String {
<caret>when (x) {
true -> return { it.toString() }
else -> return { "42" }
}
}
@@ -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);
}
}
}