"ForEach parameter unused": don't report destructured parameters
Related to KT-22068
This commit is contained in:
committed by
Mikhail Glukhikh
parent
c0c00c8c4e
commit
f3b0378918
@@ -9,6 +9,8 @@ import com.intellij.codeInspection.ProblemHighlightType
|
||||
import com.intellij.codeInspection.ProblemsHolder
|
||||
import com.intellij.psi.PsiElementVisitor
|
||||
import org.jetbrains.kotlin.descriptors.VariableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl
|
||||
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl.WithDestructuringDeclaration
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.idea.intentions.getCallableDescriptor
|
||||
import org.jetbrains.kotlin.idea.refactoring.getThisLabelName
|
||||
@@ -34,7 +36,10 @@ class ForEachParameterNotUsedInspection : AbstractKotlinInspection() {
|
||||
val descriptor = lambda.analyze()[BindingContext.FUNCTION, lambda.functionLiteral] ?: return@callExpressionVisitor
|
||||
val iterableParameter = descriptor.valueParameters.singleOrNull() ?: return@callExpressionVisitor
|
||||
|
||||
if (lambda.bodyExpression?.usesDescriptor(iterableParameter) != true && it.calleeExpression != null) {
|
||||
if (iterableParameter !is WithDestructuringDeclaration &&
|
||||
lambda.bodyExpression?.usesDescriptor(iterableParameter) != true &&
|
||||
it.calleeExpression != null) {
|
||||
|
||||
holder.registerProblem(
|
||||
it.calleeExpression!!,
|
||||
"Loop parameter '${iterableParameter.getThisLabelName()}' is unused",
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
fun foo(map: Map<String, String>) {
|
||||
map.forEach { (t, u) ->
|
||||
println("$t: $u")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user