Lift return out fix: do not suggest for labeled returns

This commit is contained in:
Mikhail Glukhikh
2017-07-07 17:37:22 +03:00
parent 41893736df
commit b0fda5f451
3 changed files with 22 additions and 1 deletions
@@ -45,7 +45,9 @@ object BranchedFoldingUtils {
fun getFoldableBranchedReturn(branch: KtExpression?): KtReturnExpression? =
(branch?.lastBlockStatementOrThis() as? KtReturnExpression)?.takeIf {
it.returnedExpression != null && it.returnedExpression !is KtLambdaExpression
it.returnedExpression != null &&
it.returnedExpression !is KtLambdaExpression &&
it.getTargetLabel() == null
}
fun checkAssignmentsMatch(a1: KtBinaryExpression, a2: KtBinaryExpression): Boolean =
@@ -0,0 +1,13 @@
// PROBLEM: none
// WITH_RUNTIME
fun test(arg: String?): Int {
arg?.let {
<caret>when (arg) {
"" -> return 1
else -> return@let 42
}
42
}
return 0
}
@@ -712,6 +712,12 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
doTest(fileName);
}
@TestMetadata("localReturns.kt")
public void testLocalReturns() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/liftOut/whenToReturn/localReturns.kt");
doTest(fileName);
}
@TestMetadata("otherReturns.kt")
public void testOtherReturns() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/liftOut/whenToReturn/otherReturns.kt");