Skip to content

Commit f0be88f

Browse files
committed
Use doResume name for suspend lambdas context (KT-16481)
#KT-16481 Fixed
1 parent dffbe0f commit f0be88f

File tree

5 files changed

+54
-8
lines changed

5 files changed

+54
-8
lines changed

compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/CoroutineCodegen.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,11 @@ class CoroutineCodegen private constructor(
328328
}
329329

330330
companion object {
331+
fun shouldCreateByLambda(
332+
originalSuspendLambdaDescriptor: CallableDescriptor,
333+
declaration: KtElement): Boolean {
334+
return (declaration is KtFunctionLiteral && originalSuspendLambdaDescriptor.isSuspendLambda)
335+
}
331336

332337
@JvmStatic
333338
fun createByLambda(
@@ -336,8 +341,7 @@ class CoroutineCodegen private constructor(
336341
declaration: KtElement,
337342
classBuilder: ClassBuilder
338343
): ClosureCodegen? {
339-
if (declaration !is KtFunctionLiteral) return null
340-
if (!originalSuspendLambdaDescriptor.isSuspendLambda) return null
344+
if (!shouldCreateByLambda(originalSuspendLambdaDescriptor, declaration)) return null
341345

342346
return CoroutineCodegen(
343347
expressionCodegen,

idea/src/org/jetbrains/kotlin/idea/debugger/DebuggerClassNameProvider.kt

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import com.intellij.psi.search.searches.ReferencesSearch
3030
import com.intellij.psi.util.PsiTreeUtil
3131
import com.intellij.xdebugger.impl.XDebugSessionImpl
3232
import org.jetbrains.kotlin.codegen.binding.CodegenBinding
33+
import org.jetbrains.kotlin.codegen.coroutines.CoroutineCodegen
3334
import org.jetbrains.kotlin.codegen.coroutines.DO_RESUME_METHOD_NAME
3435
import org.jetbrains.kotlin.codegen.coroutines.containsNonTailSuspensionCalls
3536
import org.jetbrains.kotlin.codegen.inline.InlineCodegenUtil
@@ -51,6 +52,7 @@ import org.jetbrains.kotlin.psi.*
5152
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
5253
import org.jetbrains.kotlin.psi.psiUtil.parents
5354
import org.jetbrains.kotlin.resolve.BindingContext
55+
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
5456
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
5557
import org.jetbrains.kotlin.resolve.inline.InlineUtil
5658
import org.jetbrains.kotlin.resolve.source.getPsi
@@ -221,12 +223,16 @@ class DebuggerClassNameProvider(val myDebugProcess: DebugProcess, val scopes: Li
221223
val inlineFunctionName = resolvedCall.resultingDescriptor.name
222224

223225
val ownerDescriptor = lexicalScope.ownerDescriptor
224-
val ownerDescriptorName = if (isFunctionWithSuspendStateMachine(ownerDescriptor, typeMapper.bindingContext)) {
225-
Name.identifier(DO_RESUME_METHOD_NAME)
226-
}
227-
else {
228-
ownerDescriptor.name
229-
}
226+
val ownerDeclaration = if (ownerDescriptor is DeclarationDescriptor) DescriptorToSourceUtils.getSourceFromDescriptor(ownerDescriptor) else null
227+
228+
val ownerDescriptorName =
229+
if (isFunctionWithSuspendStateMachine(ownerDescriptor, typeMapper.bindingContext) ||
230+
(ownerDescriptor is CallableDescriptor && ownerDeclaration is KtElement && CoroutineCodegen.shouldCreateByLambda(ownerDescriptor, ownerDeclaration))) {
231+
Name.identifier(DO_RESUME_METHOD_NAME)
232+
}
233+
else {
234+
ownerDescriptor.name
235+
}
230236

231237
val ownerJvmName = if (ownerDescriptorName.isSpecial) InlineCodegenUtil.SPECIAL_TRANSFORMATION_NAME else ownerDescriptorName.asString()
232238
val mangledInternalClassName =
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
LineBreakpoint created at stopInCrossinlineInSuspend.kt:12
2+
!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
3+
Connected to the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket'
4+
stopInCrossinlineInSuspend.kt:12
5+
stopInCrossinlineInSuspend.kt:13
6+
Disconnected from the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket'
7+
8+
Process finished with exit code 0
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package stopInCrossinlineInSuspend
2+
3+
import forTests.builder
4+
5+
fun main(args: Array<String>) {
6+
val a = 12
7+
8+
builder {
9+
ci {
10+
{
11+
//Breakpoint!
12+
foo(a)
13+
}()
14+
}
15+
}
16+
}
17+
18+
fun foo(a: Any? = null) {}
19+
20+
inline fun ci(crossinline builder: () -> Unit) {
21+
builder()
22+
}

idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinSteppingTestGenerated.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,12 @@ public void testStopInAnonymousFunctionInInlinedCallWithCrossInlineDex() throws
716716
doStepOverTest(fileName);
717717
}
718718

719+
@TestMetadata("stopInCrossinlineInSuspend.kt")
720+
public void testStopInCrossinlineInSuspend() throws Exception {
721+
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/debugger/tinyApp/src/stepping/stepOver/stopInCrossinlineInSuspend.kt");
722+
doStepOverTest(fileName);
723+
}
724+
719725
@TestMetadata("stopInInlineCallLocalFunLambda.kt")
720726
public void testStopInInlineCallLocalFunLambda() throws Exception {
721727
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/debugger/tinyApp/src/stepping/stepOver/stopInInlineCallLocalFunLambda.kt");

0 commit comments

Comments
 (0)