Fix problem with mutable map in "simplifiable call chain"
So #KT-20315 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
8e59d3e379
commit
45c9be2945
+4
-3
@@ -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
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
// PROBLEM: none
|
||||
// WITH_RUNTIME
|
||||
|
||||
val data = mutableMapOf<String, String>()
|
||||
val result = data.<caret>map { "${it.key}: ${it.value}" }.joinToString("\n")
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user