Don't report suspicious callable reference on invoke with parameters

So #KT-23465 Fixed
This commit is contained in:
Toshiaki Kameyama
2018-04-17 12:17:04 +03:00
committed by Mikhail Glukhikh
parent 13356d32fd
commit b5da48c566
3 changed files with 19 additions and 2 deletions
@@ -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
}
}
}
@@ -0,0 +1,7 @@
// PROBLEM: none
// WITH_RUNTIME
fun test() {
val predicate = { _: String -> true }
"".let {<caret> predicate::invoke }("123")
}
@@ -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");
}
}