diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/SimplifyForIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/SimplifyForIntention.kt index e19e563ec08..e1369d1b80f 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/SimplifyForIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/SimplifyForIntention.kt @@ -78,7 +78,9 @@ class SimplifyForIntention : SelfTargetingRangeIntention( val context = element.analyzeFullyAndGetResult().bindingContext val loopParameterDescriptor = context.get(BindingContext.VALUE_PARAMETER, loopParameter) ?: return null - val classDescriptor = loopParameterDescriptor.type.constructor.declarationDescriptor as? ClassDescriptor ?: return null + val loopParameterType = loopParameterDescriptor.type + if (loopParameterType.isMarkedNullable) return null + val classDescriptor = loopParameterType.constructor.declarationDescriptor as? ClassDescriptor ?: return null var otherUsages = false val usagesToRemove : Array diff --git a/idea/testData/intentions/iterationOverMap/DataClassNullable.kt b/idea/testData/intentions/iterationOverMap/DataClassNullable.kt new file mode 100644 index 00000000000..4aef6b9c886 --- /dev/null +++ b/idea/testData/intentions/iterationOverMap/DataClassNullable.kt @@ -0,0 +1,11 @@ +// IS_APPLICABLE: false +// WITH_RUNTIME + +data class XY(val x: String, val y: String) +fun test(xys: Array) { + for (xy in xys) { + val x = xy?.x + val y = xy?.y + println(x + y) + } +} \ 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 4790426c13f..d4caec2a16a 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java @@ -6555,6 +6555,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest { doTest(fileName); } + @TestMetadata("DataClassNullable.kt") + public void testDataClassNullable() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/iterationOverMap/DataClassNullable.kt"); + doTest(fileName); + } + @TestMetadata("DataClassParametersOrder.kt") public void testDataClassParametersOrder() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/iterationOverMap/DataClassParametersOrder.kt");