ReplacementPerformer: always copy statement to insert #KT-17273 Fixed

This commit is contained in:
Mikhail Glukhikh
2017-04-13 18:45:49 +03:00
parent 0f6b9473e9
commit 815a367978
4 changed files with 33 additions and 2 deletions
@@ -69,8 +69,7 @@ internal class ExpressionReplacementPerformer(
override fun doIt(postProcessing: (PsiChildRange) -> PsiChildRange): KtExpression? {
val insertedStatements = ArrayList<KtExpression>()
for (statement in codeToInline.statementsBefore) {
// copy the statement if it can get invalidated by findOrCreateBlockToInsertStatement()
val statementToUse = if (statement.isPhysical) statement.copy() else statement
val statementToUse = statement.copy()
val anchor = findOrCreateBlockToInsertStatement()
val block = anchor.parent as KtBlockExpression
@@ -0,0 +1,12 @@
fun sideEffect() {
println("qq")
}
fun effect(): String {
sideEffect()
return "effect"
}
fun manyParams(p1: String, p2: String, p3: String) = println(p1)
fun callManySimple() = <caret>manyParams(effect(), effect(), effect())
@@ -0,0 +1,14 @@
fun sideEffect() {
println("qq")
}
fun effect(): String {
sideEffect()
return "effect"
}
fun callManySimple() {
effect()
effect()
println(effect())
}
@@ -190,6 +190,12 @@ public class InlineTestGenerated extends AbstractInlineTest {
doTest(fileName);
}
@TestMetadata("ManyParams.kt")
public void testManyParams() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/inline/function/expressionBody/ManyParams.kt");
doTest(fileName);
}
@TestMetadata("MultipleInComposition.kt")
public void testMultipleInComposition() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/inline/function/expressionBody/MultipleInComposition.kt");