Extract Function: Support implicit abnormal exits via Nothing-typed expressions
This commit is contained in:
+3
-1
@@ -243,6 +243,8 @@ private fun ExtractionData.analyzeControlFlow(
|
||||
when {
|
||||
it !is ReturnValueInstruction && it !is ReturnNoValueInstruction && it.owner != pseudocode ->
|
||||
null
|
||||
it is UnconditionalJumpInstruction && it.targetLabel.isJumpToError ->
|
||||
it
|
||||
e != null && e !is KtBreakExpression && e !is KtContinueExpression ->
|
||||
it.previousInstructions.firstOrNull()
|
||||
else ->
|
||||
@@ -268,7 +270,7 @@ private fun ExtractionData.analyzeControlFlow(
|
||||
|| element is KtContinueExpression) {
|
||||
jumpExits.add(inst)
|
||||
}
|
||||
else if (element !is KtThrowExpression) {
|
||||
else if (element !is KtThrowExpression && !inst.targetLabel.isJumpToError) {
|
||||
defaultExits.add(inst)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
// PARAM_DESCRIPTOR: value-parameter a: kotlin.Int? defined in foo
|
||||
// PARAM_TYPES: kotlin.Int?
|
||||
fun foo(a: Int?): Int {
|
||||
<selection>val n = a ?: error("")
|
||||
return n + 1</selection>
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// WITH_RUNTIME
|
||||
// PARAM_DESCRIPTOR: value-parameter a: kotlin.Int? defined in foo
|
||||
// PARAM_TYPES: kotlin.Int?
|
||||
fun foo(a: Int?): Int {
|
||||
return i(a)
|
||||
}
|
||||
|
||||
private fun i(a: Int?): Int {
|
||||
val n = a ?: error("")
|
||||
return n + 1
|
||||
}
|
||||
+6
@@ -1682,6 +1682,12 @@ public class ExtractionTestGenerated extends AbstractExtractionTest {
|
||||
doExtractFunctionTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("implicitThrow.kt")
|
||||
public void testImplicitThrow() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/extractFunction/controlFlow/throws/implicitThrow.kt");
|
||||
doExtractFunctionTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("nonValuedReturnWithThrow.kt")
|
||||
public void testNonValuedReturnWithThrow() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/extractFunction/controlFlow/throws/nonValuedReturnWithThrow.kt");
|
||||
|
||||
Reference in New Issue
Block a user