Skip to content

Commit

Permalink
Support other kinds of variables for invoke receiver
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinkip committed Apr 17, 2020
1 parent 5a7f74c commit 7dd30eb
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
13 changes: 5 additions & 8 deletions idea/src/org/jetbrains/kotlin/idea/slicer/Slicer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions idea/testData/slicer/outflow/invokeExtensionLambda3.kt
Original file line number Diff line number Diff line change
@@ -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()
}
18 changes: 18 additions & 0 deletions idea/testData/slicer/outflow/invokeExtensionLambda3.results.txt
Original file line number Diff line number Diff line change
@@ -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>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7dd30eb

Please sign in to comment.