diff --git a/idea/src/org/jetbrains/kotlin/idea/slicer/InflowSlicer.kt b/idea/src/org/jetbrains/kotlin/idea/slicer/InflowSlicer.kt index de31abd6f91..ff46dd6774a 100644 --- a/idea/src/org/jetbrains/kotlin/idea/slicer/InflowSlicer.kt +++ b/idea/src/org/jetbrains/kotlin/idea/slicer/InflowSlicer.kt @@ -390,14 +390,24 @@ class InflowSlicer( val resolvedCall = refElement.resolveToCall() ?: return emptyList() when (val receiver = resolvedCall.extensionReceiver) { is ExpressionReceiver -> { - return listOf(KotlinSliceUsage(receiver.expression, parent, behaviour, true)) + return listOf(KotlinSliceUsage(receiver.expression, parent, behaviour, forcedExpressionMode = true)) } is ImplicitReceiver -> { - val callableDeclaration = (receiver.declarationDescriptor as? CallableDescriptor)?.originalSource?.getPsi() - val receiverTypeReference = (callableDeclaration as? KtCallableDeclaration)?.receiverTypeReference - ?: return emptyList() - return listOf(KotlinSliceUsage(receiverTypeReference, parent, behaviour, false)) + val callableDescriptor = receiver.declarationDescriptor as? CallableDescriptor ?: return emptyList() + when (val callableDeclaration = callableDescriptor.originalSource.getPsi()) { + is KtFunctionLiteral -> { + val newBehaviour = LambdaCallsBehaviour(ReceiverSliceProducer, behaviour) + return listOf(KotlinSliceUsage(callableDeclaration, parent, newBehaviour, forcedExpressionMode = true)) + } + + is KtCallableDeclaration -> { + val receiverTypeReference = callableDeclaration.receiverTypeReference ?: return emptyList() + return listOf(KotlinSliceUsage(receiverTypeReference, parent, behaviour, false)) + } + + else -> return emptyList() + } } else -> return emptyList() diff --git a/idea/testData/slicer/inflow/onFunctionReceiverType.kt b/idea/testData/slicer/inflow/onFunctionReceiverType.kt index be680697653..7735227767d 100644 --- a/idea/testData/slicer/inflow/onFunctionReceiverType.kt +++ b/idea/testData/slicer/inflow/onFunctionReceiverType.kt @@ -14,8 +14,16 @@ fun String.foo() { 1.extensionFun() extensionFun() + + with(123) { + extensionFun() + } } fun main() { "A".foo() } + +inline fun with(receiver: T, block: T.() -> R): R { + return receiver.block() +} diff --git a/idea/testData/slicer/inflow/onFunctionReceiverType.leafGroups.txt b/idea/testData/slicer/inflow/onFunctionReceiverType.leafGroups.txt index bcbf58d2aaa..24f6300d368 100644 --- a/idea/testData/slicer/inflow/onFunctionReceiverType.leafGroups.txt +++ b/idea/testData/slicer/inflow/onFunctionReceiverType.leafGroups.txt @@ -2,10 +2,10 @@ 8 fun Any.extensionFun() { 12 "".extensionFun() -20 "A".foo() +24 "A".foo() 8 fun Any.extensionFun() { 11 fun String.foo() { -20 "A".foo() +24 "A".foo() 3 KotlinUtil.extensionFun("x"); 8 fun Any.extensionFun() { @@ -15,3 +15,11 @@ 8 fun Any.extensionFun() { 14 1.extensionFun() +18 with(123) { +8 fun Any.extensionFun() { +18 [LAMBDA CALLS] with(123) { +27 [LAMBDA CALLS] inline fun with(receiver: T, block: T.() -> R): R { +28 return receiver.block() +27 inline fun with(receiver: T, block: T.() -> R): R { +18 with(123) { + diff --git a/idea/testData/slicer/inflow/onFunctionReceiverType.nullnessGroups.txt b/idea/testData/slicer/inflow/onFunctionReceiverType.nullnessGroups.txt index 9defdb355c8..5e2a6b5c985 100644 --- a/idea/testData/slicer/inflow/onFunctionReceiverType.nullnessGroups.txt +++ b/idea/testData/slicer/inflow/onFunctionReceiverType.nullnessGroups.txt @@ -5,10 +5,13 @@ 14 1.extensionFun() 8 fun Any.extensionFun() { 14 1.extensionFun() -20 "A".foo() +18 with(123) { +8 fun Any.extensionFun() { +18 [LAMBDA CALLS] with(123) { +24 "A".foo() 8 fun Any.extensionFun() { 11 fun String.foo() { -20 "A".foo() +24 "A".foo() [Other Values] 3 KotlinUtil.extensionFun("x"); diff --git a/idea/testData/slicer/inflow/onFunctionReceiverType.results.txt b/idea/testData/slicer/inflow/onFunctionReceiverType.results.txt index 2f9b039eb2a..12563321138 100644 --- a/idea/testData/slicer/inflow/onFunctionReceiverType.results.txt +++ b/idea/testData/slicer/inflow/onFunctionReceiverType.results.txt @@ -1,6 +1,11 @@ 8 fun Any.extensionFun() { 3 KotlinUtil.extensionFun("x"); 11 fun String.foo() { -20 "A".foo() +24 "A".foo() 12 "".extensionFun() 14 1.extensionFun() +18 [LAMBDA CALLS] with(123) { +27 [LAMBDA CALLS] inline fun with(receiver: T, block: T.() -> R): R { +28 return receiver.block() +27 inline fun with(receiver: T, block: T.() -> R): R { +18 with(123) {