Don't report suspicious callable reference on invoke with parameters
So #KT-23465 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
13356d32fd
commit
b5da48c566
+2
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.psi.KtLambdaExpression
|
|||||||
import org.jetbrains.kotlin.psi.ValueArgument
|
import org.jetbrains.kotlin.psi.ValueArgument
|
||||||
import org.jetbrains.kotlin.psi.lambdaExpressionVisitor
|
import org.jetbrains.kotlin.psi.lambdaExpressionVisitor
|
||||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getParameterForArgument
|
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.calls.callUtil.getParentResolvedCall
|
||||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||||
|
|
||||||
@@ -42,6 +43,7 @@ class MoveSuspiciousCallableReferenceIntoParenthesesInspection : AbstractKotlinI
|
|||||||
if (expectedType.isBuiltinFunctionalType) {
|
if (expectedType.isBuiltinFunctionalType) {
|
||||||
val returnType = expectedType.getReturnTypeFromFunctionType()
|
val returnType = expectedType.getReturnTypeFromFunctionType()
|
||||||
if (returnType.isBuiltinFunctionalTypeOrSubtype) return
|
if (returnType.isBuiltinFunctionalTypeOrSubtype) return
|
||||||
|
if (parentResolvedCall.call.callElement.getParentCall(context) != null) return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+7
@@ -0,0 +1,7 @@
|
|||||||
|
// PROBLEM: none
|
||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
val predicate = { _: String -> true }
|
||||||
|
"".let {<caret> predicate::invoke }("123")
|
||||||
|
}
|
||||||
+10
-2
@@ -2549,6 +2549,11 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
|
|||||||
runTest("idea/testData/inspectionsLocal/moveSuspiciousCallableReferenceIntoParentheses/it.kt");
|
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")
|
@TestMetadata("lambdaWithArg.kt")
|
||||||
public void testLambdaWithArg() throws Exception {
|
public void testLambdaWithArg() throws Exception {
|
||||||
runTest("idea/testData/inspectionsLocal/moveSuspiciousCallableReferenceIntoParentheses/lambdaWithArg.kt");
|
runTest("idea/testData/inspectionsLocal/moveSuspiciousCallableReferenceIntoParentheses/lambdaWithArg.kt");
|
||||||
@@ -3121,14 +3126,17 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
|
|||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
public static class RedundantSamConstructor extends AbstractLocalInspectionTest {
|
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 {
|
public void testAllFilesPresentInRedundantSamConstructor() throws Exception {
|
||||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/inspectionsLocal/redundantSamConstructor"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true);
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/inspectionsLocal/redundantSamConstructor"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("nestedInterface.kt")
|
@TestMetadata("nestedInterface.kt")
|
||||||
public void testNestedInterface() throws Exception {
|
public void testNestedInterface() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/redundantSamConstructor/nestedInterface.kt");
|
runTest("idea/testData/inspectionsLocal/redundantSamConstructor/nestedInterface.kt");
|
||||||
doTest(fileName);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user