From 7dd30eb9437da46b7438e27ac61ec982730e7085 Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Mon, 13 Apr 2020 09:42:47 +0300 Subject: [PATCH] Support other kinds of variables for invoke receiver --- .../org/jetbrains/kotlin/idea/slicer/Slicer.kt | 13 +++++-------- .../slicer/outflow/invokeExtensionLambda3.kt | 10 ++++++++++ .../outflow/invokeExtensionLambda3.results.txt | 18 ++++++++++++++++++ .../idea/slicer/SlicerTreeTestGenerated.java | 5 +++++ 4 files changed, 38 insertions(+), 8 deletions(-) create mode 100644 idea/testData/slicer/outflow/invokeExtensionLambda3.kt create mode 100644 idea/testData/slicer/outflow/invokeExtensionLambda3.results.txt diff --git a/idea/src/org/jetbrains/kotlin/idea/slicer/Slicer.kt b/idea/src/org/jetbrains/kotlin/idea/slicer/Slicer.kt index 6040760920d..5e139d2df08 100644 --- a/idea/src/org/jetbrains/kotlin/idea/slicer/Slicer.kt +++ b/idea/src/org/jetbrains/kotlin/idea/slicer/Slicer.kt @@ -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)) } } } diff --git a/idea/testData/slicer/outflow/invokeExtensionLambda3.kt b/idea/testData/slicer/outflow/invokeExtensionLambda3.kt new file mode 100644 index 00000000000..1ae12230242 --- /dev/null +++ b/idea/testData/slicer/outflow/invokeExtensionLambda3.kt @@ -0,0 +1,10 @@ +// FLOW: OUT + +fun String.foo(p: String) { + val v = bar(p) { this } +} + +fun bar(receiver: T, block: T.() -> R): R { + val b = block + return receiver.b() +} diff --git a/idea/testData/slicer/outflow/invokeExtensionLambda3.results.txt b/idea/testData/slicer/outflow/invokeExtensionLambda3.results.txt new file mode 100644 index 00000000000..95ea185ff14 --- /dev/null +++ b/idea/testData/slicer/outflow/invokeExtensionLambda3.results.txt @@ -0,0 +1,18 @@ +3 fun String.foo(p: String) { +4 val v = bar(p) { this } +7 fun bar(receiver: T, block: T.() -> R): R { +9 return receiver.b() +8 [LAMBDA RECEIVER IN] val b = block +8 [LAMBDA RECEIVER IN] val b = block +7 [LAMBDA RECEIVER IN] fun bar(receiver: T, block: T.() -> R): R { +4 [LAMBDA RECEIVER IN] val v = bar(p) { this } +4 val v = bar(p) { this } +4 val v = bar(p) { this } +4 [LAMBDA CALLS] val v = bar(p) { this } +7 [LAMBDA CALLS] fun bar(receiver: T, block: T.() -> R): R { +8 [LAMBDA CALLS] val b = block +8 [LAMBDA CALLS] val b = block +9 return receiver.b() +7 fun bar(receiver: T, block: T.() -> R): R { +4 val v = bar(p) { this } +4 val v = bar(p) { this } diff --git a/idea/tests/org/jetbrains/kotlin/idea/slicer/SlicerTreeTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/slicer/SlicerTreeTestGenerated.java index be6dec89b05..e5f984eb730 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/slicer/SlicerTreeTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/slicer/SlicerTreeTestGenerated.java @@ -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");