diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/CoroutineCodegen.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/CoroutineCodegen.kt index 90c8f0cee87..2151b78ae3e 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/CoroutineCodegen.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/CoroutineCodegen.kt @@ -328,6 +328,11 @@ class CoroutineCodegen private constructor( } companion object { + fun shouldCreateByLambda( + originalSuspendLambdaDescriptor: CallableDescriptor, + declaration: KtElement): Boolean { + return (declaration is KtFunctionLiteral && originalSuspendLambdaDescriptor.isSuspendLambda) + } @JvmStatic fun createByLambda( @@ -336,8 +341,7 @@ class CoroutineCodegen private constructor( declaration: KtElement, classBuilder: ClassBuilder ): ClosureCodegen? { - if (declaration !is KtFunctionLiteral) return null - if (!originalSuspendLambdaDescriptor.isSuspendLambda) return null + if (!shouldCreateByLambda(originalSuspendLambdaDescriptor, declaration)) return null return CoroutineCodegen( expressionCodegen, diff --git a/idea/src/org/jetbrains/kotlin/idea/debugger/DebuggerClassNameProvider.kt b/idea/src/org/jetbrains/kotlin/idea/debugger/DebuggerClassNameProvider.kt index cca4547efef..70575486e54 100644 --- a/idea/src/org/jetbrains/kotlin/idea/debugger/DebuggerClassNameProvider.kt +++ b/idea/src/org/jetbrains/kotlin/idea/debugger/DebuggerClassNameProvider.kt @@ -30,6 +30,7 @@ import com.intellij.psi.search.searches.ReferencesSearch import com.intellij.psi.util.PsiTreeUtil import com.intellij.xdebugger.impl.XDebugSessionImpl import org.jetbrains.kotlin.codegen.binding.CodegenBinding +import org.jetbrains.kotlin.codegen.coroutines.CoroutineCodegen import org.jetbrains.kotlin.codegen.coroutines.DO_RESUME_METHOD_NAME import org.jetbrains.kotlin.codegen.coroutines.containsNonTailSuspensionCalls import org.jetbrains.kotlin.codegen.inline.InlineCodegenUtil @@ -51,6 +52,7 @@ import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType import org.jetbrains.kotlin.psi.psiUtil.parents import org.jetbrains.kotlin.resolve.BindingContext +import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall import org.jetbrains.kotlin.resolve.inline.InlineUtil import org.jetbrains.kotlin.resolve.source.getPsi @@ -221,12 +223,16 @@ class DebuggerClassNameProvider(val myDebugProcess: DebugProcess, val scopes: Li val inlineFunctionName = resolvedCall.resultingDescriptor.name val ownerDescriptor = lexicalScope.ownerDescriptor - val ownerDescriptorName = if (isFunctionWithSuspendStateMachine(ownerDescriptor, typeMapper.bindingContext)) { - Name.identifier(DO_RESUME_METHOD_NAME) - } - else { - ownerDescriptor.name - } + val ownerDeclaration = if (ownerDescriptor is DeclarationDescriptor) DescriptorToSourceUtils.getSourceFromDescriptor(ownerDescriptor) else null + + val ownerDescriptorName = + if (isFunctionWithSuspendStateMachine(ownerDescriptor, typeMapper.bindingContext) || + (ownerDescriptor is CallableDescriptor && ownerDeclaration is KtElement && CoroutineCodegen.shouldCreateByLambda(ownerDescriptor, ownerDeclaration))) { + Name.identifier(DO_RESUME_METHOD_NAME) + } + else { + ownerDescriptor.name + } val ownerJvmName = if (ownerDescriptorName.isSpecial) InlineCodegenUtil.SPECIAL_TRANSFORMATION_NAME else ownerDescriptorName.asString() val mangledInternalClassName = diff --git a/idea/testData/debugger/tinyApp/outs/stopInCrossinlineInSuspend.out b/idea/testData/debugger/tinyApp/outs/stopInCrossinlineInSuspend.out new file mode 100644 index 00000000000..bdc71ba3d98 --- /dev/null +++ b/idea/testData/debugger/tinyApp/outs/stopInCrossinlineInSuspend.out @@ -0,0 +1,8 @@ +LineBreakpoint created at stopInCrossinlineInSuspend.kt:12 +!JDK_HOME!\bin\java -agentlib:jdwp=transport=dt_socket,address=!HOST_NAME!:!HOST_PORT!,suspend=y,server=n -Dfile.encoding=!FILE_ENCODING! -classpath !OUTPUT_PATH!;!KOTLIN_RUNTIME!;!CUSTOM_LIBRARY!;!RT_JAR! stopInCrossinlineInSuspend.StopInCrossinlineInSuspendKt +Connected to the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket' +stopInCrossinlineInSuspend.kt:12 +stopInCrossinlineInSuspend.kt:13 +Disconnected from the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket' + +Process finished with exit code 0 diff --git a/idea/testData/debugger/tinyApp/src/stepping/stepOver/stopInCrossinlineInSuspend.kt b/idea/testData/debugger/tinyApp/src/stepping/stepOver/stopInCrossinlineInSuspend.kt new file mode 100644 index 00000000000..cf93f3050a2 --- /dev/null +++ b/idea/testData/debugger/tinyApp/src/stepping/stepOver/stopInCrossinlineInSuspend.kt @@ -0,0 +1,22 @@ +package stopInCrossinlineInSuspend + +import forTests.builder + +fun main(args: Array) { + val a = 12 + + builder { + ci { + { + //Breakpoint! + foo(a) + }() + } + } +} + +fun foo(a: Any? = null) {} + +inline fun ci(crossinline builder: () -> Unit) { + builder() +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinSteppingTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinSteppingTestGenerated.java index b53d7528008..28a7ec087d9 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinSteppingTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinSteppingTestGenerated.java @@ -716,6 +716,12 @@ public class KotlinSteppingTestGenerated extends AbstractKotlinSteppingTest { doStepOverTest(fileName); } + @TestMetadata("stopInCrossinlineInSuspend.kt") + public void testStopInCrossinlineInSuspend() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/debugger/tinyApp/src/stepping/stepOver/stopInCrossinlineInSuspend.kt"); + doStepOverTest(fileName); + } + @TestMetadata("stopInInlineCallLocalFunLambda.kt") public void testStopInInlineCallLocalFunLambda() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/debugger/tinyApp/src/stepping/stepOver/stopInInlineCallLocalFunLambda.kt");