Tracking of implicit receiver from enclosing lambda
This commit is contained in:
@@ -390,14 +390,24 @@ class InflowSlicer(
|
|||||||
val resolvedCall = refElement.resolveToCall() ?: return emptyList()
|
val resolvedCall = refElement.resolveToCall() ?: return emptyList()
|
||||||
when (val receiver = resolvedCall.extensionReceiver) {
|
when (val receiver = resolvedCall.extensionReceiver) {
|
||||||
is ExpressionReceiver -> {
|
is ExpressionReceiver -> {
|
||||||
return listOf(KotlinSliceUsage(receiver.expression, parent, behaviour, true))
|
return listOf(KotlinSliceUsage(receiver.expression, parent, behaviour, forcedExpressionMode = true))
|
||||||
}
|
}
|
||||||
|
|
||||||
is ImplicitReceiver -> {
|
is ImplicitReceiver -> {
|
||||||
val callableDeclaration = (receiver.declarationDescriptor as? CallableDescriptor)?.originalSource?.getPsi()
|
val callableDescriptor = receiver.declarationDescriptor as? CallableDescriptor ?: return emptyList()
|
||||||
val receiverTypeReference = (callableDeclaration as? KtCallableDeclaration)?.receiverTypeReference
|
when (val callableDeclaration = callableDescriptor.originalSource.getPsi()) {
|
||||||
?: return emptyList()
|
is KtFunctionLiteral -> {
|
||||||
return listOf(KotlinSliceUsage(receiverTypeReference, parent, behaviour, false))
|
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()
|
else -> return emptyList()
|
||||||
|
|||||||
@@ -14,8 +14,16 @@ fun String.foo() {
|
|||||||
1.extensionFun()
|
1.extensionFun()
|
||||||
|
|
||||||
extensionFun()
|
extensionFun()
|
||||||
|
|
||||||
|
with(123) {
|
||||||
|
extensionFun()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun main() {
|
fun main() {
|
||||||
"A".foo()
|
"A".foo()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline fun <T, R> with(receiver: T, block: T.() -> R): R {
|
||||||
|
return receiver.block()
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,10 +2,10 @@
|
|||||||
8 fun <bold>Any</bold>.extensionFun() {
|
8 fun <bold>Any</bold>.extensionFun() {
|
||||||
12 <bold>""</bold>.extensionFun()
|
12 <bold>""</bold>.extensionFun()
|
||||||
|
|
||||||
20 <bold>"A"</bold>.foo()
|
24 <bold>"A"</bold>.foo()
|
||||||
8 fun <bold>Any</bold>.extensionFun() {
|
8 fun <bold>Any</bold>.extensionFun() {
|
||||||
11 fun <bold>String</bold>.foo() {
|
11 fun <bold>String</bold>.foo() {
|
||||||
20 <bold>"A"</bold>.foo()
|
24 <bold>"A"</bold>.foo()
|
||||||
|
|
||||||
3 KotlinUtil.extensionFun(<bold>"x"</bold>);
|
3 KotlinUtil.extensionFun(<bold>"x"</bold>);
|
||||||
8 fun <bold>Any</bold>.extensionFun() {
|
8 fun <bold>Any</bold>.extensionFun() {
|
||||||
@@ -15,3 +15,11 @@
|
|||||||
8 fun <bold>Any</bold>.extensionFun() {
|
8 fun <bold>Any</bold>.extensionFun() {
|
||||||
14 <bold>1</bold>.extensionFun()
|
14 <bold>1</bold>.extensionFun()
|
||||||
|
|
||||||
|
18 with(<bold>123</bold>) {
|
||||||
|
8 fun <bold>Any</bold>.extensionFun() {
|
||||||
|
18 [LAMBDA CALLS] with(123) <bold>{</bold>
|
||||||
|
27 [LAMBDA CALLS] inline fun <T, R> with(receiver: T, <bold>block: T.() -> R</bold>): R {
|
||||||
|
28 return <bold>receiver</bold>.block()
|
||||||
|
27 inline fun <T, R> with(<bold>receiver: T</bold>, block: T.() -> R): R {
|
||||||
|
18 with(<bold>123</bold>) {
|
||||||
|
|
||||||
|
|||||||
@@ -5,10 +5,13 @@
|
|||||||
14 <bold>1</bold>.extensionFun()
|
14 <bold>1</bold>.extensionFun()
|
||||||
8 fun <bold>Any</bold>.extensionFun() {
|
8 fun <bold>Any</bold>.extensionFun() {
|
||||||
14 <bold>1</bold>.extensionFun()
|
14 <bold>1</bold>.extensionFun()
|
||||||
20 <bold>"A"</bold>.foo()
|
18 with(123) <bold>{</bold>
|
||||||
|
8 fun <bold>Any</bold>.extensionFun() {
|
||||||
|
18 [LAMBDA CALLS] with(123) <bold>{</bold>
|
||||||
|
24 <bold>"A"</bold>.foo()
|
||||||
8 fun <bold>Any</bold>.extensionFun() {
|
8 fun <bold>Any</bold>.extensionFun() {
|
||||||
11 fun <bold>String</bold>.foo() {
|
11 fun <bold>String</bold>.foo() {
|
||||||
20 <bold>"A"</bold>.foo()
|
24 <bold>"A"</bold>.foo()
|
||||||
|
|
||||||
[Other Values]
|
[Other Values]
|
||||||
3 KotlinUtil.extensionFun(<bold>"x"</bold>);
|
3 KotlinUtil.extensionFun(<bold>"x"</bold>);
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
8 fun <bold>Any</bold>.extensionFun() {
|
8 fun <bold>Any</bold>.extensionFun() {
|
||||||
3 KotlinUtil.extensionFun(<bold>"x"</bold>);
|
3 KotlinUtil.extensionFun(<bold>"x"</bold>);
|
||||||
11 fun <bold>String</bold>.foo() {
|
11 fun <bold>String</bold>.foo() {
|
||||||
20 <bold>"A"</bold>.foo()
|
24 <bold>"A"</bold>.foo()
|
||||||
12 <bold>""</bold>.extensionFun()
|
12 <bold>""</bold>.extensionFun()
|
||||||
14 <bold>1</bold>.extensionFun()
|
14 <bold>1</bold>.extensionFun()
|
||||||
|
18 [LAMBDA CALLS] with(123) <bold>{</bold>
|
||||||
|
27 [LAMBDA CALLS] inline fun <T, R> with(receiver: T, <bold>block: T.() -> R</bold>): R {
|
||||||
|
28 return <bold>receiver</bold>.block()
|
||||||
|
27 inline fun <T, R> with(<bold>receiver: T</bold>, block: T.() -> R): R {
|
||||||
|
18 with(<bold>123</bold>) {
|
||||||
|
|||||||
Reference in New Issue
Block a user