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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user