Use withIndex intention: fix false positive for destructuring declaration

#KT-30341 Fixed
This commit is contained in:
Toshiaki Kameyama
2019-03-18 18:27:13 +09:00
committed by Mikhail Glukhikh
parent cbdc79fcda
commit bd3d5a9dbb
3 changed files with 14 additions and 0 deletions
@@ -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"
@@ -0,0 +1,8 @@
// WITH_RUNTIME
// IS_APPLICABLE: false
fun foo(list: List<Pair<String, String>>) {
var index = 0
<caret>for ((s1, s2) in list) {
index++
}
}
@@ -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");