Move lambda argument out of parentheses: fix false negative when function type is type parameter
#KT-26979 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
b4789b95ef
commit
8e61a13809
@@ -45,6 +45,7 @@ import org.jetbrains.kotlin.resolve.calls.model.ArgumentMatch
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.isError
|
||||
import org.jetbrains.kotlin.types.typeUtil.isTypeParameter
|
||||
import org.jetbrains.kotlin.utils.KotlinExceptionWithAttachments
|
||||
import org.jetbrains.kotlin.utils.SmartList
|
||||
|
||||
@@ -138,8 +139,10 @@ fun KtCallExpression.canMoveLambdaOutsideParentheses(): Boolean {
|
||||
// if there are functions among candidates but none of them have last function parameter then not show the intention
|
||||
if (candidates.isNotEmpty() && candidates.none { candidate ->
|
||||
val params = candidate.valueParameters
|
||||
params.lastOrNull()?.type?.isFunctionOrSuspendFunctionType == true &&
|
||||
params.count { it.type.isFunctionOrSuspendFunctionType } == lambdaArgumentCount + referenceArgumentCount
|
||||
val lastParamType = params.lastOrNull()?.type
|
||||
(lastParamType?.isFunctionOrSuspendFunctionType == true || lastParamType?.isTypeParameter() == true) && params.count {
|
||||
it.type.let { type -> type.isFunctionOrSuspendFunctionType || type.isTypeParameter() }
|
||||
} == lambdaArgumentCount + referenceArgumentCount
|
||||
}
|
||||
) return false
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
fun <T> foo(t: T) {}
|
||||
|
||||
fun test() {
|
||||
foo(<caret>{ "a" })
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
fun <T> foo(t: T) {}
|
||||
|
||||
fun test() {
|
||||
foo { "a" }
|
||||
}
|
||||
+5
@@ -4167,6 +4167,11 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
|
||||
public void testSuspendLambda() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/moveLambdaOutsideParentheses/suspendLambda.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("typeParameter.kt")
|
||||
public void testTypeParameter() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/moveLambdaOutsideParentheses/typeParameter.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/inspectionsLocal/moveSuspiciousCallableReferenceIntoParentheses")
|
||||
|
||||
Reference in New Issue
Block a user