Inline Function: fix false positive with inner function with 'return'
#KT-34190 Fixed
This commit is contained in:
committed by
igoriakovlev
parent
04e8cba857
commit
ff76ba52d8
@@ -36,6 +36,7 @@ import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.collectDescendantsOfType
|
||||
import org.jetbrains.kotlin.psi.psiUtil.createSmartPointer
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
@@ -134,6 +135,8 @@ internal fun buildCodeToInline(
|
||||
val statements = bodyCopy.statements
|
||||
|
||||
val returnStatements = bodyCopy.collectDescendantsOfType<KtReturnExpression> {
|
||||
val function = it.getStrictParentOfType<KtFunction>()
|
||||
if (function != null && function != declaration) return@collectDescendantsOfType false
|
||||
it.getLabelName().let { it == null || it == declaration.name }
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
fun foo() {
|
||||
object {
|
||||
fun bar(): String {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun main() {
|
||||
<caret>foo()
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fun main() {
|
||||
object {
|
||||
fun bar(): String {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fun foo() {
|
||||
fun bar(): String {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
fun main() {
|
||||
<caret>foo()
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
fun main() {
|
||||
fun bar(): String {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
+10
@@ -383,6 +383,16 @@ public class InlineTestGenerated extends AbstractInlineTest {
|
||||
runTest("idea/testData/refactoring/inline/function/returnAtEnd/DefaultParameter.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("InnerFunction.kt")
|
||||
public void testInnerFunction() throws Exception {
|
||||
runTest("idea/testData/refactoring/inline/function/returnAtEnd/InnerFunction.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("InnerFunction2.kt")
|
||||
public void testInnerFunction2() throws Exception {
|
||||
runTest("idea/testData/refactoring/inline/function/returnAtEnd/InnerFunction2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("MultipleStatements.kt")
|
||||
public void testMultipleStatements() throws Exception {
|
||||
runTest("idea/testData/refactoring/inline/function/returnAtEnd/MultipleStatements.kt");
|
||||
|
||||
Reference in New Issue
Block a user