diff --git a/plugins/kotlin/uast/uast-kotlin-base/src/org/jetbrains/uast/kotlin/expressions/KotlinUFunctionCallExpression.kt b/plugins/kotlin/uast/uast-kotlin-base/src/org/jetbrains/uast/kotlin/expressions/KotlinUFunctionCallExpression.kt index 1769a8f3421c..4560d277d705 100644 --- a/plugins/kotlin/uast/uast-kotlin-base/src/org/jetbrains/uast/kotlin/expressions/KotlinUFunctionCallExpression.kt +++ b/plugins/kotlin/uast/uast-kotlin-base/src/org/jetbrains/uast/kotlin/expressions/KotlinUFunctionCallExpression.kt @@ -291,6 +291,14 @@ class KotlinUFunctionCallExpression( // Bail out for non-instance functions if (isStatic || callableDeclaration !is PsiMethod) return null + val containingUMethod = getContainingUMethod() + val extensionReceiver = containingUMethod?.uastParameters?.firstOrNull() as? KotlinReceiverUParameter + // Extension receiver of the containing method + if (extensionReceiver != null && extensionReceiver.javaPsi.type == receiverType) { + // Implicit $this$extension + return KotlinUImplicitExtensionReceiver(extensionReceiver, receiverType, this) + } + val implicitReceiver = if (baseResolveProviderService.isResolvedToExtension(sourcePsi)) { // Extension receiver of PsiParameter @@ -347,6 +355,28 @@ class KotlinUFunctionCallExpression( get() = implicitReceiver } + private class KotlinUImplicitExtensionReceiver( + val extensionReceiver: KotlinReceiverUParameter, + val receiverType: PsiType?, + uasParent: UElement, + ) : KotlinAbstractUExpression(uasParent), UThisExpression { + override val label: String? + get() = null + + override val labelIdentifier: UIdentifier? + get() = null + + override fun getExpressionType() = receiverType + + override fun resolve(): PsiElement? = extensionReceiver.javaPsi + + override val sourcePsi: PsiElement? + get() = null + + override val javaPsi: PsiElement? + get() = extensionReceiver.javaPsi + } + private class KotlinUImplicitLambdaReceiver( val lambdaReceiver: UParameter?, val receiverType: PsiType?,