diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/ImplicitThisInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/ImplicitThisInspection.kt index 509b1696754..fa390949420 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/ImplicitThisInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/ImplicitThisInspection.kt @@ -23,6 +23,7 @@ import com.intellij.codeInspection.ProblemsHolder import com.intellij.openapi.project.Project import org.jetbrains.kotlin.descriptors.CallableDescriptor import org.jetbrains.kotlin.idea.caches.resolve.analyze +import org.jetbrains.kotlin.idea.intentions.getCallableDescriptor import org.jetbrains.kotlin.idea.util.getFactoryForImplicitReceiverWithSubtypeOf import org.jetbrains.kotlin.idea.util.getResolutionScope import org.jetbrains.kotlin.psi.* @@ -52,8 +53,10 @@ class ImplicitThisInspection : AbstractKotlinInspection() { val context = reference.analyze() val scope = reference.getResolutionScope(context) ?: return - val descriptor = context[BindingContext.REFERENCE_TARGET, reference] as? CallableDescriptor ?: return - val receiverDescriptor = descriptor.extensionReceiverParameter ?: descriptor.dispatchReceiverParameter ?: return + val descriptor = reference.getCallableDescriptor() ?: return + val receiverDescriptor = descriptor.extensionReceiverParameter + ?: descriptor.dispatchReceiverParameter + ?: return val receiverType = receiverDescriptor.type val expressionFactory = scope.getFactoryForImplicitReceiverWithSubtypeOf(receiverType) ?: return diff --git a/idea/testData/inspectionsLocal/implicitThis/functionWithReceiver.kt b/idea/testData/inspectionsLocal/implicitThis/functionWithReceiver.kt new file mode 100644 index 00000000000..5ad588653df --- /dev/null +++ b/idea/testData/inspectionsLocal/implicitThis/functionWithReceiver.kt @@ -0,0 +1,3 @@ +fun CharSequence.foo(bar: CharSequence.() -> Unit){ + bar() +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/implicitThis/functionWithReceiver.kt.after b/idea/testData/inspectionsLocal/implicitThis/functionWithReceiver.kt.after new file mode 100644 index 00000000000..93013401949 --- /dev/null +++ b/idea/testData/inspectionsLocal/implicitThis/functionWithReceiver.kt.after @@ -0,0 +1,3 @@ +fun CharSequence.foo(bar: CharSequence.() -> Unit){ + this.bar() +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java index 5628df2e1c2..c37e5fc4cd2 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java @@ -1485,6 +1485,12 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest { doTest(fileName); } + @TestMetadata("functionWithReceiver.kt") + public void testFunctionWithReceiver() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/implicitThis/functionWithReceiver.kt"); + doTest(fileName); + } + @TestMetadata("multipleReceivers.kt") public void testMultipleReceivers() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/implicitThis/multipleReceivers.kt");