diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/CodeFragmentCodegen.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/CodeFragmentCodegen.kt index 4f88ef95720..079c37aafa2 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/CodeFragmentCodegen.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/CodeFragmentCodegen.kt @@ -63,7 +63,18 @@ class CodeFragmentCodegen private constructor( override fun generateBody() { genConstructor() - genMethod(classContext.intoFunction(methodDescriptor)) + + val methodContext = object : MethodContext(methodDescriptor, classContext.contextKind, classContext, null, false) { + override fun getAccessorForSuperCallIfNeeded( + descriptor: D, + superCallTarget: ClassDescriptor?, + state: GenerationState + ): D { + return descriptor + } + } + + genMethod(methodContext) } override fun generateKotlinMetadataAnnotation() { 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 ee9eeb5ed6e..e8dd376e679 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 @@ -169,8 +169,16 @@ class CodeFragmentParameterAnalyzer( return null } - override fun visitSuperExpression(expression: KtSuperExpression, data: Unit?): Void { - throw EvaluateExceptionUtil.createEvaluateException("Evaluation of 'super' call expression is not supported") + override fun visitSuperExpression(expression: KtSuperExpression, data: Unit?): Void? { + val type = bindingContext[BindingContext.THIS_TYPE_FOR_SUPER_EXPRESSION, expression] ?: return null + val descriptor = type.constructor.declarationDescriptor as? ClassDescriptor ?: return null + + parameters.getOrPut(descriptor) { + val name = descriptor.name.asString() + Smart(Dumb(Kind.DISPATCH_RECEIVER, "", "super@$name"), type, descriptor) + } + + return null } }, Unit) diff --git a/idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/errors.kt b/idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/errors.kt index d042f5f544c..32b69b91f70 100644 --- a/idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/errors.kt +++ b/idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/errors.kt @@ -28,4 +28,4 @@ open class Base { // RESULT: Expecting an element; looking at ERROR_ELEMENT '(1,6) in /fragment.kt // EXPRESSION: super.baseFun() -// RESULT: Evaluation of 'super' call expression is not supported \ No newline at end of file +// RESULT: VOID_VALUE \ No newline at end of file diff --git a/idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/errors.out b/idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/errors.out index c0c42e25cfd..e2a9de4a13e 100644 --- a/idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/errors.out +++ b/idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/errors.out @@ -2,6 +2,7 @@ LineBreakpoint created at errors.kt:13 Run Java Connected to the target VM errors.kt:13 +Compile bytecode for super.baseFun() Compile bytecode for prop += 1 prop2 +=2 prop + prop2 diff --git a/idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/superCallsCaptured.kt b/idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/superCallsCaptured.kt new file mode 100644 index 00000000000..b75b716ffed --- /dev/null +++ b/idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/superCallsCaptured.kt @@ -0,0 +1,29 @@ +package superCallsCaptured + +fun main() { + Bar().foo() +} + +open class Foo { + open fun foo() = 5 +} + +class Bar : Foo() { + override fun foo(): Int { + block { + //Breakpoint! + val a = this@Bar + } + return 6 + } +} + +fun block(block: () -> Unit) { + block() +} + +// EXPRESSION: foo() +// RESULT: 6: I + +// EXPRESSION: super.foo() +// RESULT: 5: I \ No newline at end of file diff --git a/idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/superCallsCaptured.out b/idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/superCallsCaptured.out new file mode 100644 index 00000000000..de7d57cc0c5 --- /dev/null +++ b/idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/superCallsCaptured.out @@ -0,0 +1,9 @@ +LineBreakpoint created at superCallsCaptured.kt:15 +Run Java +Connected to the target VM +superCallsCaptured.kt:15 +Compile bytecode for foo() +Compile bytecode for super.foo() +Disconnected from the target VM + +Process finished with exit code 0 diff --git a/idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/superCallsSimple.kt b/idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/superCallsSimple.kt new file mode 100644 index 00000000000..e0b38068a6d --- /dev/null +++ b/idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/superCallsSimple.kt @@ -0,0 +1,22 @@ +package superCallsSimple + +fun main() { + Bar().foo() +} + +open class Foo { + open fun foo() = 5 +} + +class Bar : Foo() { + override fun foo(): Int { + //Breakpoint! + return 6 + } +} + +// EXPRESSION: foo() +// RESULT: 6: I + +// EXPRESSION: super.foo() +// RESULT: 5: I \ No newline at end of file diff --git a/idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/superCallsSimple.out b/idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/superCallsSimple.out new file mode 100644 index 00000000000..80f2ab9bc80 --- /dev/null +++ b/idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/superCallsSimple.out @@ -0,0 +1,9 @@ +LineBreakpoint created at superCallsSimple.kt:14 +Run Java +Connected to the target VM +superCallsSimple.kt:14 +Compile bytecode for foo() +Compile bytecode for super.foo() +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 b16dd2596fe..cafd7087553 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/KotlinEvaluateExpressionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/KotlinEvaluateExpressionTestGenerated.java @@ -396,6 +396,16 @@ public class KotlinEvaluateExpressionTestGenerated extends AbstractKotlinEvaluat runTest("idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/stdlib.kt"); } + @TestMetadata("superCallsCaptured.kt") + public void testSuperCallsCaptured() throws Exception { + runTest("idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/superCallsCaptured.kt"); + } + + @TestMetadata("superCallsSimple.kt") + public void testSuperCallsSimple() throws Exception { + runTest("idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/superCallsSimple.kt"); + } + @TestMetadata("synchronizedBlock.kt") public void testSynchronizedBlock() throws Exception { runTest("idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/synchronizedBlock.kt");