Convert to lambda reference: don't suggest when lambda is argument for 'suspend' function parameter
#KT-16907 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
b75ab5c832
commit
59f70a912a
@@ -9,6 +9,7 @@ import com.intellij.openapi.editor.Editor
|
|||||||
import org.jetbrains.kotlin.builtins.getReturnTypeFromFunctionType
|
import org.jetbrains.kotlin.builtins.getReturnTypeFromFunctionType
|
||||||
import org.jetbrains.kotlin.builtins.isExtensionFunctionType
|
import org.jetbrains.kotlin.builtins.isExtensionFunctionType
|
||||||
import org.jetbrains.kotlin.builtins.isFunctionType
|
import org.jetbrains.kotlin.builtins.isFunctionType
|
||||||
|
import org.jetbrains.kotlin.builtins.isSuspendFunctionType
|
||||||
import org.jetbrains.kotlin.config.LanguageFeature
|
import org.jetbrains.kotlin.config.LanguageFeature
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||||
@@ -137,7 +138,8 @@ open class ConvertLambdaToReferenceIntention(text: String) :
|
|||||||
if (lambdaParent is KtLambdaArgument) {
|
if (lambdaParent is KtLambdaArgument) {
|
||||||
val outerCalleeDescriptor = lambdaParent.outerCalleeDescriptor() ?: return false
|
val outerCalleeDescriptor = lambdaParent.outerCalleeDescriptor() ?: return false
|
||||||
val lambdaParameterType = outerCalleeDescriptor.valueParameters.lastOrNull()?.type
|
val lambdaParameterType = outerCalleeDescriptor.valueParameters.lastOrNull()?.type
|
||||||
if (lambdaParameterType != null && lambdaParameterType.isFunctionType) {
|
if (lambdaParameterType?.isSuspendFunctionType == true) return false
|
||||||
|
if (lambdaParameterType?.isFunctionType == true) {
|
||||||
// For lambda parameter with receiver, conversion is not allowed
|
// For lambda parameter with receiver, conversion is not allowed
|
||||||
if (lambdaParameterType.isExtensionFunctionType) return false
|
if (lambdaParameterType.isExtensionFunctionType) return false
|
||||||
// Special Unit case (non-Unit returning lambda is accepted here, but non-Unit returning reference is not)
|
// Special Unit case (non-Unit returning lambda is accepted here, but non-Unit returning reference is not)
|
||||||
|
|||||||
+15
@@ -0,0 +1,15 @@
|
|||||||
|
// IS_APPLICABLE: false
|
||||||
|
|
||||||
|
fun coroutine(block: suspend () -> Unit) {}
|
||||||
|
|
||||||
|
suspend fun testAction(obj: Any, action: suspend (Any) -> Unit) {
|
||||||
|
action(action)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun println(message: Any?) {}
|
||||||
|
|
||||||
|
fun main() = coroutine {
|
||||||
|
testAction("OK") {<caret>
|
||||||
|
println(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4974,6 +4974,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
|||||||
runTest("idea/testData/intentions/convertLambdaToReference/suspendFun.kt");
|
runTest("idea/testData/intentions/convertLambdaToReference/suspendFun.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("suspendFunctionParameter.kt")
|
||||||
|
public void testSuspendFunctionParameter() throws Exception {
|
||||||
|
runTest("idea/testData/intentions/convertLambdaToReference/suspendFunctionParameter.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("syntheticProperty.kt")
|
@TestMetadata("syntheticProperty.kt")
|
||||||
public void testSyntheticProperty() throws Exception {
|
public void testSyntheticProperty() throws Exception {
|
||||||
runTest("idea/testData/intentions/convertLambdaToReference/syntheticProperty.kt");
|
runTest("idea/testData/intentions/convertLambdaToReference/syntheticProperty.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user