diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/SimplifyForIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/SimplifyForIntention.kt index 18d88292dca..536b9fcc11f 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/SimplifyForIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/SimplifyForIntention.kt @@ -57,7 +57,8 @@ class SimplifyForIntention : SelfTargetingRangeIntention( override fun applicabilityRange(element: KtForExpression): TextRange? { if (element.destructuringParameter != null) return null - if (collectPropertiesToRemove(element) != null) { + val propertiesToRemove = collectPropertiesToRemove(element) + if (propertiesToRemove != null && propertiesToRemove.first.isNotEmpty()) { return element.loopParameter!!.textRange } return null diff --git a/idea/testData/intentions/iterationOverMap/DataClassUnused.kt b/idea/testData/intentions/iterationOverMap/DataClassUnused.kt new file mode 100644 index 00000000000..f3ea00fbd46 --- /dev/null +++ b/idea/testData/intentions/iterationOverMap/DataClassUnused.kt @@ -0,0 +1,7 @@ +// IS_APPLICABLE: false +// WITH_RUNTIME + +data class XY(val x: String, val y: String) +fun test(xys: Array) { + for (xy in xys) {} +} \ 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 1639fa4b582..8d07af44241 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java @@ -6537,6 +6537,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest { doTest(fileName); } + @TestMetadata("DataClassUnused.kt") + public void testDataClassUnused() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/iterationOverMap/DataClassUnused.kt"); + doTest(fileName); + } + @TestMetadata("EntriesCallIsMissing.kt") public void testEntriesCallIsMissing() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/iterationOverMap/EntriesCallIsMissing.kt");