diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/RemoveRedundantSpreadOperatorInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/RemoveRedundantSpreadOperatorInspection.kt index 1a7bd60d99c..a4ad0a2b069 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/RemoveRedundantSpreadOperatorInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/RemoveRedundantSpreadOperatorInspection.kt @@ -62,13 +62,17 @@ class RemoveRedundantSpreadOperatorQuickfix : LocalQuickFix { // Arguments under arrayOf or [] val innerArgumentExpressions = when (spreadArgumentExpression) { - is KtCallExpression -> spreadArgumentExpression.valueArgumentList?.arguments?.map { it.getArgumentExpression() } - is KtCollectionLiteralExpression -> spreadArgumentExpression.getInnerExpressions() + is KtCallExpression -> spreadArgumentExpression.valueArgumentList?.arguments?.map { + it.getArgumentExpression() to it.isSpread + } + is KtCollectionLiteralExpression -> spreadArgumentExpression.getInnerExpressions().map { it to false } else -> null } ?: return val factory = KtPsiFactory(project) - innerArgumentExpressions.reversed().forEach { outerArgumentList.addArgumentAfter(factory.createArgument(it), spreadValueArgument) } + innerArgumentExpressions.reversed().forEach { (expression, isSpread) -> + outerArgumentList.addArgumentAfter(factory.createArgument(expression, isSpread = isSpread), spreadValueArgument) + } outerArgumentList.removeArgument(spreadValueArgument) } } \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantSpreadOperator/spredOperatorArgument.kt b/idea/testData/inspectionsLocal/removeRedundantSpreadOperator/spredOperatorArgument.kt new file mode 100644 index 00000000000..0ea1504a597 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantSpreadOperator/spredOperatorArgument.kt @@ -0,0 +1,6 @@ +fun foo(vararg xs: String) { +} + +fun bar(ys: Array) { + foo(*arrayOf(*ys, "zzz")) +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantSpreadOperator/spredOperatorArgument.kt.after b/idea/testData/inspectionsLocal/removeRedundantSpreadOperator/spredOperatorArgument.kt.after new file mode 100644 index 00000000000..a99f1ecb159 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantSpreadOperator/spredOperatorArgument.kt.after @@ -0,0 +1,6 @@ +fun foo(vararg xs: String) { +} + +fun bar(ys: Array) { + foo(*ys, "zzz") +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java index 8b993bd1056..6f620f2989e 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java @@ -5141,6 +5141,11 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest { public void testShortArrayOf() throws Exception { runTest("idea/testData/inspectionsLocal/removeRedundantSpreadOperator/shortArrayOf.kt"); } + + @TestMetadata("spredOperatorArgument.kt") + public void testSpredOperatorArgument() throws Exception { + runTest("idea/testData/inspectionsLocal/removeRedundantSpreadOperator/spredOperatorArgument.kt"); + } } @TestMetadata("idea/testData/inspectionsLocal/removeSetterParameterType")