Support other kinds of variables for invoke receiver

This commit is contained in:
Valentin Kipyatkov
2020-04-13 09:42:47 +03:00
parent 5a7f74c250
commit 7dd30eb943
4 changed files with 38 additions and 8 deletions
@@ -298,14 +298,11 @@ abstract class Slicer(
val dispatchReceiverPseudoValue = instruction.receiverValues.entries
.singleOrNull { it.value == dispatchReceiver }?.key
?: return true
when (val createdAt = dispatchReceiverPseudoValue.createdAt) {
is ReadValueInstruction -> {
val accessedDescriptor = createdAt.target.accessedDescriptor
if (accessedDescriptor is ValueParameterDescriptor) {
val accessedDeclaration = accessedDescriptor.originalSource.getPsi()
accessedDeclaration?.passToProcessor(mode.withBehaviour(LambdaReceiverInflowBehaviour))
}
}
val createdAt = dispatchReceiverPseudoValue.createdAt
val accessedDescriptor = (createdAt as ReadValueInstruction?)?.target?.accessedDescriptor
if (accessedDescriptor is VariableDescriptor) {
val accessedDeclaration = accessedDescriptor.originalSource.getPsi()
accessedDeclaration?.passToProcessor(mode.withBehaviour(LambdaReceiverInflowBehaviour))
}
}
}
+10
View File
@@ -0,0 +1,10 @@
// FLOW: OUT
fun String.foo(<caret>p: String) {
val v = bar(p) { this }
}
fun <T, R> bar(receiver: T, block: T.() -> R): R {
val b = block
return receiver.b()
}
@@ -0,0 +1,18 @@
3 fun String.foo(<bold>p: String</bold>) {
4 val v = bar(<bold>p</bold>) { this }
7 fun <T, R> bar(<bold>receiver: T</bold>, block: T.() -> R): R {
9 return <bold>receiver</bold>.b()
8 [LAMBDA RECEIVER IN] val <bold>b = block</bold>
8 [LAMBDA RECEIVER IN] val b = <bold>block</bold>
7 [LAMBDA RECEIVER IN] fun <T, R> bar(receiver: T, <bold>block: T.() -> R</bold>): R {
4 [LAMBDA RECEIVER IN] val v = bar(p) <bold>{ this }</bold>
4 val v = bar(p) { <bold>this</bold> }
4 val v = bar(p) <bold>{ this }</bold>
4 [LAMBDA CALLS] val v = bar(p) <bold>{ this }</bold>
7 [LAMBDA CALLS] fun <T, R> bar(receiver: T, <bold>block: T.() -> R</bold>): R {
8 [LAMBDA CALLS] val b = <bold>block</bold>
8 [LAMBDA CALLS] val <bold>b = block</bold>
9 return receiver.<bold>b()</bold>
7 fun <T, R> <bold>bar(receiver: T, block: T.() -> R): R {</bold>
4 val v = <bold>bar(p) { this }</bold>
4 val <bold>v = bar(p) { this }</bold>
@@ -608,6 +608,11 @@ public class SlicerTreeTestGenerated extends AbstractSlicerTreeTest {
runTest("idea/testData/slicer/outflow/invokeExtensionLambda2.kt");
}
@TestMetadata("invokeExtensionLambda3.kt")
public void testInvokeExtensionLambda3() throws Exception {
runTest("idea/testData/slicer/outflow/invokeExtensionLambda3.kt");
}
@TestMetadata("invokeLambdaSecondParam.kt")
public void testInvokeLambdaSecondParam() throws Exception {
runTest("idea/testData/slicer/outflow/invokeLambdaSecondParam.kt");