diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/ReplaceWithAnnotationAnalyzer.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/ReplaceWithAnnotationAnalyzer.kt index f66466125f6..d487567b6b9 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/ReplaceWithAnnotationAnalyzer.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/ReplaceWithAnnotationAnalyzer.kt @@ -130,7 +130,8 @@ object ReplaceWithAnnotationAnalyzer { } } - for ((expr, receiverExpression) in receiversToAdd) { + // add receivers in reverse order because arguments of a call were processed after the callee's name + for ((expr, receiverExpression) in receiversToAdd.reverse()) { val expressionToReplace = expr.getParent() as? JetCallExpression ?: expr val newExpr = expressionToReplace.replaced(psiFactory.createExpressionByPattern("$0.$1", receiverExpression, expressionToReplace)) if (expressionToReplace == expression) { diff --git a/idea/testData/quickfix/deprecatedSymbolUsage/addImplicitReceiverNested.kt b/idea/testData/quickfix/deprecatedSymbolUsage/addImplicitReceiverNested.kt new file mode 100644 index 00000000000..175a656e62b --- /dev/null +++ b/idea/testData/quickfix/deprecatedSymbolUsage/addImplicitReceiverNested.kt @@ -0,0 +1,15 @@ +// "Replace with 'newFun1(newFun2())'" "true" + +class X { + @deprecated("", ReplaceWith("newFun1(newFun2())")) + fun oldFun() { + newFun1(newFun2()) + } + + fun newFun1(p: Int): Int = p + fun newFun2(): Int = 1 +} + +fun foo(x: X) { + x.oldFun() +} diff --git a/idea/testData/quickfix/deprecatedSymbolUsage/addImplicitReceiverNested.kt.after b/idea/testData/quickfix/deprecatedSymbolUsage/addImplicitReceiverNested.kt.after new file mode 100644 index 00000000000..e4f466d84f0 --- /dev/null +++ b/idea/testData/quickfix/deprecatedSymbolUsage/addImplicitReceiverNested.kt.after @@ -0,0 +1,15 @@ +// "Replace with 'newFun1(newFun2())'" "true" + +class X { + @deprecated("", ReplaceWith("newFun1(newFun2())")) + fun oldFun() { + newFun1(newFun2()) + } + + fun newFun1(p: Int): Int = p + fun newFun2(): Int = 1 +} + +fun foo(x: X) { + x.newFun1(x.newFun2()) +} diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java index 52ed50ba1ed..0ed8297914c 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java @@ -2862,6 +2862,12 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) public static class DeprecatedSymbolUsage extends AbstractQuickFixTest { + @TestMetadata("addImplicitReceiverNested.kt") + public void testAddImplicitReceiverNested() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/deprecatedSymbolUsage/addImplicitReceiverNested.kt"); + doTest(fileName); + } + public void testAllFilesPresentInDeprecatedSymbolUsage() throws Exception { JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/deprecatedSymbolUsage"), Pattern.compile("^(\\w+)\\.kt$"), true); }