Scope function conversion: do not suggest when invoked without receiver

#KT-35525 Fixed
This commit is contained in:
Toshiaki Kameyama
2019-12-18 21:57:49 +09:00
committed by Ilya Kirillov
parent 8ba5548a0f
commit f3be3f449a
3 changed files with 13 additions and 3 deletions
@@ -80,9 +80,9 @@ private fun getCounterpart(expression: KtCallExpression): String? {
}
val bindingContext = callee.analyze(BodyResolveMode.PARTIAL)
val resolvedCall = callee.getResolvedCall(bindingContext) ?: return null
if (resolvedCall.resultingDescriptor.fqNameSafe.asString() == "kotlin.$calleeName" &&
nameResolvesToStdlib(expression, bindingContext, counterpartName)
) {
val descriptor = resolvedCall.resultingDescriptor
if (descriptor.dispatchReceiverParameter == null && descriptor.extensionReceiverParameter == null) return null
if (descriptor.fqNameSafe.asString() == "kotlin.$calleeName" && nameResolvesToStdlib(expression, bindingContext, counterpartName)) {
return counterpartName
}
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
// PROBLEM: none
fun hello() {
<caret>run { }
}
@@ -12246,6 +12246,11 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
runTest("idea/testData/inspectionsLocal/scopeFunctions/runToLet/capturedIt.kt");
}
@TestMetadata("noReceiver.kt")
public void testNoReceiver() throws Exception {
runTest("idea/testData/inspectionsLocal/scopeFunctions/runToLet/noReceiver.kt");
}
@TestMetadata("simple.kt")
public void testSimple() throws Exception {
runTest("idea/testData/inspectionsLocal/scopeFunctions/runToLet/simple.kt");