Do not report "redundant arrow" with parameters without expected type
#KT-29049 Fixed Part of KT-29005
This commit is contained in:
@@ -14,10 +14,12 @@ import com.intellij.openapi.project.Project
|
|||||||
import com.intellij.openapi.util.TextRange
|
import com.intellij.openapi.util.TextRange
|
||||||
import com.intellij.psi.PsiElementVisitor
|
import com.intellij.psi.PsiElementVisitor
|
||||||
import org.jetbrains.kotlin.KtNodeTypes
|
import org.jetbrains.kotlin.KtNodeTypes
|
||||||
|
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.endOffset
|
import org.jetbrains.kotlin.psi.psiUtil.endOffset
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
||||||
|
import org.jetbrains.kotlin.resolve.BindingContext
|
||||||
import org.jetbrains.kotlin.resolve.calls.util.isSingleUnderscore
|
import org.jetbrains.kotlin.resolve.calls.util.isSingleUnderscore
|
||||||
|
|
||||||
class RedundantLambdaArrowInspection : AbstractKotlinInspection() {
|
class RedundantLambdaArrowInspection : AbstractKotlinInspection() {
|
||||||
@@ -42,6 +44,11 @@ class RedundantLambdaArrowInspection : AbstractKotlinInspection() {
|
|||||||
if (callee != null && callee.getReferencedName() == "forEach" && singleParameter?.name != "it") return
|
if (callee != null && callee.getReferencedName() == "forEach" && singleParameter?.name != "it") return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (parameters.isNotEmpty()) {
|
||||||
|
val context = lambdaExpression.analyze()
|
||||||
|
if (context[BindingContext.EXPECTED_EXPRESSION_TYPE, lambdaExpression] == null) return
|
||||||
|
}
|
||||||
|
|
||||||
val startOffset = functionLiteral.startOffset
|
val startOffset = functionLiteral.startOffset
|
||||||
holder.registerProblem(
|
holder.registerProblem(
|
||||||
holder.manager.createProblemDescriptor(
|
holder.manager.createProblemDescriptor(
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
// PROBLEM: none
|
||||||
|
|
||||||
|
fun foo(x: Int) = x
|
||||||
|
|
||||||
|
val x = { it: Int <caret>-> foo(it) }
|
||||||
+5
@@ -4938,6 +4938,11 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
|
|||||||
runTest("idea/testData/inspectionsLocal/redundantLambdaArrow/it.kt");
|
runTest("idea/testData/inspectionsLocal/redundantLambdaArrow/it.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("noExpectedType.kt")
|
||||||
|
public void testNoExpectedType() throws Exception {
|
||||||
|
runTest("idea/testData/inspectionsLocal/redundantLambdaArrow/noExpectedType.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("simple.kt")
|
@TestMetadata("simple.kt")
|
||||||
public void testSimple() throws Exception {
|
public void testSimple() throws Exception {
|
||||||
runTest("idea/testData/inspectionsLocal/redundantLambdaArrow/simple.kt");
|
runTest("idea/testData/inspectionsLocal/redundantLambdaArrow/simple.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user