diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/collections/SimplifiableCallChainInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/collections/SimplifiableCallChainInspection.kt index 262e02bc84e..9b41d22e0da 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/collections/SimplifiableCallChainInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/collections/SimplifiableCallChainInspection.kt @@ -59,9 +59,10 @@ class SimplifiableCallChainInspection : AbstractKotlinInspection() { // Do not apply on maps due to lack of relevant stdlib functions val firstReceiverType = firstResolvedCall.extensionReceiver?.type - if (firstReceiverType != null) { - val mapType = builtIns.map.defaultType - if (firstReceiverType.isSubtypeOf(mapType)) return + val firstReceiverRawType = firstReceiverType?.constructor?.declarationDescriptor?.defaultType + if (firstReceiverRawType != null) { + if (firstReceiverRawType.isSubtypeOf(builtIns.map.defaultType) || + firstReceiverRawType.isSubtypeOf(builtIns.mutableMap.defaultType)) return } // Do not apply for lambdas with return inside diff --git a/idea/testData/inspectionsLocal/collections/simplifiableCallChain/joinToStringOnMap.kt b/idea/testData/inspectionsLocal/collections/simplifiableCallChain/joinToStringOnMap.kt new file mode 100644 index 00000000000..935e6ae0b03 --- /dev/null +++ b/idea/testData/inspectionsLocal/collections/simplifiableCallChain/joinToStringOnMap.kt @@ -0,0 +1,5 @@ +// PROBLEM: none +// WITH_RUNTIME + +val data = mutableMapOf() +val result = data.map { "${it.key}: ${it.value}" }.joinToString("\n") \ 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 768de1e8144..028e4fbfef0 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java @@ -232,6 +232,12 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest { doTest(fileName); } + @TestMetadata("joinToStringOnMap.kt") + public void testJoinToStringOnMap() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/collections/simplifiableCallChain/joinToStringOnMap.kt"); + doTest(fileName); + } + @TestMetadata("joinToStringViaBuilder.kt") public void testJoinToStringViaBuilder() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/collections/simplifiableCallChain/joinToStringViaBuilder.kt");