Lambda to reference: fix false positive for parameter' class reference

So #KT-22041 Fixed
This commit is contained in:
Toshiaki Kameyama
2018-05-25 07:10:09 +03:00
committed by Mikhail Glukhikh
parent 271cbc1dd3
commit b5e3db1811
5 changed files with 18 additions and 1 deletions
@@ -97,10 +97,13 @@ open class ConvertLambdaToReferenceIntention(text: String) :
}
}
val lambdaValueParameterDescriptors = context[FUNCTION, lambdaExpression.functionLiteral]?.valueParameters ?: return false
if (explicitReceiver is KtClassLiteralExpression
&& explicitReceiver.receiverExpression?.getCallableDescriptor() in lambdaValueParameterDescriptors
) return false
val explicitReceiverDescriptor = (explicitReceiver as? KtNameReferenceExpression)?.let {
context[REFERENCE_TARGET, it]
} as? ValueDescriptor
val lambdaValueParameterDescriptors = context[FUNCTION, lambdaExpression.functionLiteral]?.valueParameters ?: return false
val lambdaParameterAsExplicitReceiver = when (noBoundReferences) {
true -> explicitReceiver != null
false -> explicitReceiverDescriptor != null && explicitReceiverDescriptor == lambdaValueParameterDescriptors.firstOrNull()
@@ -0,0 +1 @@
val isInt: (Any) -> Boolean = <caret>{ a -> Int::class.isInstance(a) }
@@ -0,0 +1 @@
val isInt: (Any) -> Boolean = <caret>Int::class::isInstance
@@ -0,0 +1,2 @@
// IS_APPLICABLE: false
val f: (Any) -> Boolean = <caret>{ a -> a::class.isInstance(a) }
@@ -5070,6 +5070,16 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
runTest("idea/testData/intentions/convertLambdaToReference/argumentWithReceiver.kt");
}
@TestMetadata("classReference.kt")
public void testClassReference() throws Exception {
runTest("idea/testData/intentions/convertLambdaToReference/classReference.kt");
}
@TestMetadata("classReference2.kt")
public void testClassReference2() throws Exception {
runTest("idea/testData/intentions/convertLambdaToReference/classReference2.kt");
}
@TestMetadata("companion.kt")
public void testCompanion() throws Exception {
runTest("idea/testData/intentions/convertLambdaToReference/companion.kt");