diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/matchAndConvert.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/matchAndConvert.kt index 87c878a0fca..82dc02c12d3 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/matchAndConvert.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/matchAndConvert.kt @@ -379,6 +379,7 @@ data class IntroduceIndexData( ) fun matchIndexToIntroduce(loop: KtForExpression, reformat: Boolean): IntroduceIndexData? { + if (loop.destructuringDeclaration != null) return null val (inputVariable, indexVariable) = extractLoopData(loop) ?: return null if (indexVariable != null) return null // loop is already with "withIndex" diff --git a/idea/testData/intentions/useWithIndex/destructuringDeclaration.kt b/idea/testData/intentions/useWithIndex/destructuringDeclaration.kt new file mode 100644 index 00000000000..035d079c4f9 --- /dev/null +++ b/idea/testData/intentions/useWithIndex/destructuringDeclaration.kt @@ -0,0 +1,8 @@ +// WITH_RUNTIME +// IS_APPLICABLE: false +fun foo(list: List>) { + var index = 0 + for ((s1, s2) in list) { + index++ + } +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java index 556602efee0..c29a9571af6 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java @@ -17553,6 +17553,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest { runTest("idea/testData/intentions/useWithIndex/customTypeWithIterator.kt"); } + @TestMetadata("destructuringDeclaration.kt") + public void testDestructuringDeclaration() throws Exception { + runTest("idea/testData/intentions/useWithIndex/destructuringDeclaration.kt"); + } + @TestMetadata("indexIncrementTwice.kt") public void testIndexIncrementTwice() throws Exception { runTest("idea/testData/intentions/useWithIndex/indexIncrementTwice.kt");