From e5b4b03314e72a83292cb13b23c20402456a604d Mon Sep 17 00:00:00 2001 From: Toshiaki Kameyama Date: Tue, 24 Mar 2020 19:30:24 +0900 Subject: [PATCH] RedundantLambdaArrowInspection: fix false positive when receiver is qualified expression #KT-37502 Fixed --- .../idea/inspections/RedundantLambdaArrowInspection.kt | 3 ++- .../redundantLambdaArrow/typeParameter4.kt | 8 ++++++++ .../idea/inspections/LocalInspectionTestGenerated.java | 5 +++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 idea/testData/inspectionsLocal/redundantLambdaArrow/typeParameter4.kt diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantLambdaArrowInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantLambdaArrowInspection.kt index 220476f6149..3bc4241087f 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantLambdaArrowInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantLambdaArrowInspection.kt @@ -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 diff --git a/idea/testData/inspectionsLocal/redundantLambdaArrow/typeParameter4.kt b/idea/testData/inspectionsLocal/redundantLambdaArrow/typeParameter4.kt new file mode 100644 index 00000000000..ba159397c50 --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantLambdaArrow/typeParameter4.kt @@ -0,0 +1,8 @@ +// PROBLEM: none +object A { + fun foo(f: (T) -> Int) {} +} + +fun test() { + A.foo { _: String -> 24 } +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java index ce4f6ac49e0..90879b66bf9 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java @@ -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");