diff --git a/idea/jvm-debugger/jvm-debugger-evaluation/src/org/jetbrains/kotlin/idea/debugger/evaluate/compilation/CodeFragmentParameterAnalyzer.kt b/idea/jvm-debugger/jvm-debugger-evaluation/src/org/jetbrains/kotlin/idea/debugger/evaluate/compilation/CodeFragmentParameterAnalyzer.kt index c2b33d51151..20a618e9d1c 100644 --- a/idea/jvm-debugger/jvm-debugger-evaluation/src/org/jetbrains/kotlin/idea/debugger/evaluate/compilation/CodeFragmentParameterAnalyzer.kt +++ b/idea/jvm-debugger/jvm-debugger-evaluation/src/org/jetbrains/kotlin/idea/debugger/evaluate/compilation/CodeFragmentParameterAnalyzer.kt @@ -75,6 +75,12 @@ class CodeFragmentParameterAnalyzer( } private fun processResolvedCall(resolvedCall: ResolvedCall<*>, expression: KtSimpleNameExpression) { + if (resolvedCall is VariableAsFunctionResolvedCall) { + processResolvedCall(resolvedCall.functionCall, expression) + processResolvedCall(resolvedCall.variableCall, expression) + return + } + // Capture dispatch receiver for the extension callable run { val descriptor = resolvedCall.resultingDescriptor @@ -84,7 +90,8 @@ class CodeFragmentParameterAnalyzer( && extensionParameter != null && containingClass != null ) { if (containingClass.kind != ClassKind.OBJECT) { - processDispatchReceiver(containingClass) + val parameter = processDispatchReceiver(containingClass) + checkBounds(descriptor, expression, parameter) } } } @@ -130,21 +137,16 @@ class CodeFragmentParameterAnalyzer( // If a reference has receivers, we can calculate its value using them, no need to capture if (!processed) { - if (resolvedCall is VariableAsFunctionResolvedCall) { - processResolvedCall(resolvedCall.functionCall, expression) - processResolvedCall(resolvedCall.variableCall, expression) - } else { - processDescriptor(resolvedCall.resultingDescriptor, expression) - } + val descriptor = resolvedCall.resultingDescriptor + val parameter = processDescriptor(descriptor, expression) + checkBounds(descriptor, expression, parameter) } } - private fun processDescriptor(descriptor: DeclarationDescriptor, expression: KtSimpleNameExpression) { - val parameter = processDebugLabel(descriptor) + private fun processDescriptor(descriptor: DeclarationDescriptor, expression: KtSimpleNameExpression): Smart? { + return processDebugLabel(descriptor) ?: processCoroutineContextCall(descriptor) ?: processSimpleNameExpression(descriptor, expression) - - checkBounds(descriptor, expression, parameter) } override fun visitThisExpression(expression: KtThisExpression, data: Unit?): Void? { diff --git a/idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/variableAsFunction.kt b/idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/variableAsFunction.kt new file mode 100644 index 00000000000..2827536bc07 --- /dev/null +++ b/idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/variableAsFunction.kt @@ -0,0 +1,25 @@ +package variableAsFunction + +fun main() { + class Foo + + class Bar { + operator fun Foo.invoke(f: Int) = f + } + + with (Bar()) { + block { + val foo = Foo() + //Breakpoint! + val y = foo(5) + } + } +} + +fun block(block: () -> Unit) { + block() +} + + +// EXPRESSION: foo(5) +// RESULT: 5: I \ No newline at end of file diff --git a/idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/variableAsFunction.out b/idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/variableAsFunction.out new file mode 100644 index 00000000000..17d84fcd45e --- /dev/null +++ b/idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/variableAsFunction.out @@ -0,0 +1,8 @@ +LineBreakpoint created at variableAsFunction.kt:14 +Run Java +Connected to the target VM +variableAsFunction.kt:14 +Compile bytecode for foo(5) +Disconnected from the target VM + +Process finished with exit code 0 diff --git a/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/KotlinEvaluateExpressionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/KotlinEvaluateExpressionTestGenerated.java index c4eecbdaccd..c0645664bd7 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/KotlinEvaluateExpressionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/KotlinEvaluateExpressionTestGenerated.java @@ -441,6 +441,11 @@ public class KotlinEvaluateExpressionTestGenerated extends AbstractKotlinEvaluat runTest("idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/valueParameterName.kt"); } + @TestMetadata("variableAsFunction.kt") + public void testVariableAsFunction() throws Exception { + runTest("idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/variableAsFunction.kt"); + } + @TestMetadata("vars.kt") public void testVars() throws Exception { runTest("idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/vars.kt");