Lambda --> reference: correct handling of parameter-less function
Issue #KT-15556 Fixed
This commit is contained in:
@@ -99,8 +99,8 @@ class ConvertLambdaToReferenceIntention : SelfTargetingOffsetIndependentIntentio
|
||||
val lambdaParameterAsExplicitReceiver = explicitReceiverDescriptor != null &&
|
||||
explicitReceiverDescriptor == lambdaValueParameterDescriptors.firstOrNull()
|
||||
val explicitReceiverShift = if (lambdaParameterAsExplicitReceiver) 1 else 0
|
||||
val lambdaParametersCount =
|
||||
if (lambdaExpression.functionLiteral.hasParameterSpecification()) lambdaExpression.valueParameters.size else 1
|
||||
|
||||
val lambdaParametersCount = lambdaValueParameterDescriptors.size
|
||||
if (lambdaParametersCount != callableArgumentsCount + explicitReceiverShift) return false
|
||||
|
||||
if (explicitReceiver != null && explicitReceiverDescriptor != null && lambdaParameterAsExplicitReceiver) {
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
class Foo
|
||||
fun usage(f: () -> Foo) {}
|
||||
fun test() {
|
||||
usage {<caret> Foo() }
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
class Foo
|
||||
fun usage(f: () -> Foo) {}
|
||||
fun test() {
|
||||
usage(::Foo)
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// IS_APPLICABLE: false
|
||||
// IS_APPLICABLE: true
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo() {
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// IS_APPLICABLE: true
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo() {
|
||||
listOf(1).forEach { run(it::bar) }
|
||||
}
|
||||
|
||||
fun Int.bar() {
|
||||
}
|
||||
@@ -4340,6 +4340,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("defaultConstructor.kt")
|
||||
public void testDefaultConstructor() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertLambdaToReference/defaultConstructor.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("defaultNamed.kt")
|
||||
public void testDefaultNamed() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertLambdaToReference/defaultNamed.kt");
|
||||
|
||||
Reference in New Issue
Block a user