diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/MoveSuspiciousCallableReferenceIntoParenthesesInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/MoveSuspiciousCallableReferenceIntoParenthesesInspection.kt index 3a692860647..5e828f65ac1 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/MoveSuspiciousCallableReferenceIntoParenthesesInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/MoveSuspiciousCallableReferenceIntoParenthesesInspection.kt @@ -24,6 +24,7 @@ import org.jetbrains.kotlin.psi.KtLambdaExpression import org.jetbrains.kotlin.psi.ValueArgument import org.jetbrains.kotlin.psi.lambdaExpressionVisitor import org.jetbrains.kotlin.resolve.calls.callUtil.getParameterForArgument +import org.jetbrains.kotlin.resolve.calls.callUtil.getParentCall import org.jetbrains.kotlin.resolve.calls.callUtil.getParentResolvedCall import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode @@ -42,6 +43,7 @@ class MoveSuspiciousCallableReferenceIntoParenthesesInspection : AbstractKotlinI if (expectedType.isBuiltinFunctionalType) { val returnType = expectedType.getReturnTypeFromFunctionType() if (returnType.isBuiltinFunctionalTypeOrSubtype) return + if (parentResolvedCall.call.callElement.getParentCall(context) != null) return } } } diff --git a/idea/testData/inspectionsLocal/moveSuspiciousCallableReferenceIntoParentheses/lambdaInvoke.kt b/idea/testData/inspectionsLocal/moveSuspiciousCallableReferenceIntoParentheses/lambdaInvoke.kt new file mode 100644 index 00000000000..161dc33fdc2 --- /dev/null +++ b/idea/testData/inspectionsLocal/moveSuspiciousCallableReferenceIntoParentheses/lambdaInvoke.kt @@ -0,0 +1,7 @@ +// PROBLEM: none +// WITH_RUNTIME + +fun test() { + val predicate = { _: String -> true } + "".let { predicate::invoke }("123") +} \ 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 cdff9898ffa..e816cabda9e 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java @@ -2549,6 +2549,11 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest { runTest("idea/testData/inspectionsLocal/moveSuspiciousCallableReferenceIntoParentheses/it.kt"); } + @TestMetadata("lambdaInvoke.kt") + public void testLambdaInvoke() throws Exception { + runTest("idea/testData/inspectionsLocal/moveSuspiciousCallableReferenceIntoParentheses/lambdaInvoke.kt"); + } + @TestMetadata("lambdaWithArg.kt") public void testLambdaWithArg() throws Exception { runTest("idea/testData/inspectionsLocal/moveSuspiciousCallableReferenceIntoParentheses/lambdaWithArg.kt"); @@ -3121,14 +3126,17 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest { @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) public static class RedundantSamConstructor extends AbstractLocalInspectionTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); + } + public void testAllFilesPresentInRedundantSamConstructor() throws Exception { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/inspectionsLocal/redundantSamConstructor"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true); } @TestMetadata("nestedInterface.kt") public void testNestedInterface() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/redundantSamConstructor/nestedInterface.kt"); - doTest(fileName); + runTest("idea/testData/inspectionsLocal/redundantSamConstructor/nestedInterface.kt"); } }