RedundantLambdaArrowInspection: fix false positive when receiver is qualified expression

#KT-37502 Fixed
This commit is contained in:
Toshiaki Kameyama
2020-03-24 19:30:24 +09:00
committed by Ilya Kirillov
parent 487e1ddddc
commit e5b4b03314
3 changed files with 15 additions and 1 deletions
@@ -90,9 +90,9 @@ class RedundantLambdaArrowInspection : AbstractKotlinInspection() {
}
private fun KtCallExpression.isApplicableCall(lambdaExpression: KtLambdaExpression, lambdaContext: BindingContext): Boolean {
val offset = lambdaExpression.textOffset - textOffset
val dotQualifiedExpression = parent as? KtDotQualifiedExpression
return if (dotQualifiedExpression == null) {
val offset = lambdaExpression.textOffset - textOffset
replaceWithCopyWithResolveCheck(
resolveStrategy = { expr, context ->
expr.getResolvedCall(context)?.resultingDescriptor
@@ -103,6 +103,7 @@ private fun KtCallExpression.isApplicableCall(lambdaExpression: KtLambdaExpressi
}
)
} else {
val offset = lambdaExpression.textOffset - dotQualifiedExpression.textOffset
dotQualifiedExpression.replaceWithCopyWithResolveCheck(
resolveStrategy = { expr, context ->
expr.selectorExpression.getResolvedCall(context)?.resultingDescriptor
@@ -0,0 +1,8 @@
// PROBLEM: none
object A {
fun <T> foo(f: (T) -> Int) {}
}
fun test() {
A.foo { <caret>_: String -> 24 }
}
@@ -7712,6 +7712,11 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
runTest("idea/testData/inspectionsLocal/redundantLambdaArrow/typeParameter3_ni.kt");
}
@TestMetadata("typeParameter4.kt")
public void testTypeParameter4() throws Exception {
runTest("idea/testData/inspectionsLocal/redundantLambdaArrow/typeParameter4.kt");
}
@TestMetadata("underscore.kt")
public void testUnderscore() throws Exception {
runTest("idea/testData/inspectionsLocal/redundantLambdaArrow/underscore.kt");