diff --git a/kotlin-checks-test-sources/src/main/kotlin/checks/CollectionShouldBeImmutableCheckSample.kt b/kotlin-checks-test-sources/src/main/kotlin/checks/CollectionShouldBeImmutableCheckSample.kt index 4102258d1..ec96d5db9 100644 --- a/kotlin-checks-test-sources/src/main/kotlin/checks/CollectionShouldBeImmutableCheckSample.kt +++ b/kotlin-checks-test-sources/src/main/kotlin/checks/CollectionShouldBeImmutableCheckSample.kt @@ -249,4 +249,7 @@ class CollectionShouldBeImmutableCheckSample { private fun nonCompliantParameterOnFileLevel(list: MutableList): Int { // Noncompliant return list.reduce { acc, it -> acc + it} -} \ No newline at end of file +} + +// https://sonarsource.atlassian.net/browse/SONARKT-388 +private fun intersectionType(t: T) = if (t is String) listOf(t) else emptyList() diff --git a/sonar-kotlin-checks/src/main/java/org/sonarsource/kotlin/checks/CollectionShouldBeImmutableCheck.kt b/sonar-kotlin-checks/src/main/java/org/sonarsource/kotlin/checks/CollectionShouldBeImmutableCheck.kt index 0f77e777e..3d0848717 100644 --- a/sonar-kotlin-checks/src/main/java/org/sonarsource/kotlin/checks/CollectionShouldBeImmutableCheck.kt +++ b/sonar-kotlin-checks/src/main/java/org/sonarsource/kotlin/checks/CollectionShouldBeImmutableCheck.kt @@ -153,7 +153,10 @@ class CollectionShouldBeImmutableCheck : AbstractCheck() { val functionDescriptor = call.getResolvedCall(bindingContext)?.resultingDescriptor val parameterTypes = functionDescriptor?.valueParameters if (parameterTypes != null) { - val fullyQualifiedTypes = parameterTypes.map { it.type.getKotlinTypeFqName(false) } + val fullyQualifiedTypes = parameterTypes.map { + if (it.type.constructor.declarationDescriptor == null) null + else it.type.getKotlinTypeFqName(false) + } call.valueArguments.zip(fullyQualifiedTypes).filter { it.second in mutableCollections }.map { it.first } } else { call.valueArguments