Convert lambda to reference: no more allowed for extension KFunction parameters #KT-13527 Fixed
(cherry picked from commit 84c4ff7)
This commit is contained in:
committed by
Mikhail Glukhikh
parent
ec41289664
commit
863e4afc7b
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.idea.intentions
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import org.jetbrains.kotlin.builtins.getReturnTypeFromFunctionType
|
||||
import org.jetbrains.kotlin.builtins.isExtensionFunctionType
|
||||
import org.jetbrains.kotlin.builtins.isFunctionType
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
@@ -65,6 +66,8 @@ class ConvertLambdaToReferenceIntention : SelfTargetingOffsetIndependentIntentio
|
||||
val outerCalleeDescriptor = lambdaParent.outerCalleeDescriptor() ?: return false
|
||||
val lambdaParameterType = outerCalleeDescriptor.valueParameters.lastOrNull()?.type
|
||||
if (lambdaParameterType != null && lambdaParameterType.isFunctionType) {
|
||||
// For lambda parameter with receiver, conversion is not allowed
|
||||
if (lambdaParameterType.isExtensionFunctionType) return false
|
||||
// Special Unit case (non-Unit returning lambda is accepted here, but non-Unit returning reference is not)
|
||||
lambdaMustReturnUnit = getReturnTypeFromFunctionType(lambdaParameterType).isUnit()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
// IS_APPLICABLE: false
|
||||
|
||||
fun callMe(s: String) {
|
||||
}
|
||||
|
||||
fun body(receiver: String.(String) -> Unit) {
|
||||
}
|
||||
|
||||
fun usage() {
|
||||
body { <caret>callMe(it) }
|
||||
}
|
||||
@@ -3883,6 +3883,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/intentions/convertLambdaToReference"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("argumentWithReceiver.kt")
|
||||
public void testArgumentWithReceiver() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertLambdaToReference/argumentWithReceiver.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("constructor.kt")
|
||||
public void testConstructor() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertLambdaToReference/constructor.kt");
|
||||
|
||||
Reference in New Issue
Block a user