Fix transforming of coroutine's create when it is suspend lambda with receiver

Unlike ordinary lambdas suspend lambdas has create method which invokes
the constructor of the lambda object (continuation).
The inliner could not cope with this.
The previous change fixed the case of suspend lambda without receiver.
This change adds support of suspend lambdas with receiver.

 #KT-21605: Fixed
This commit is contained in:
Ilmir Usmanov
2018-03-23 19:57:20 +03:00
parent e96b5f3117
commit 58bac6882d
6 changed files with 59 additions and 2 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
@@ -291,7 +291,7 @@ class MethodInliner(
}
val isContinuationCreate = isContinuation && oldInfo != null && resultNode.name == "create" &&
resultNode.desc.startsWith("(" + CONTINUATION_ASM_TYPE.descriptor)
resultNode.desc.endsWith(")" + CONTINUATION_ASM_TYPE.descriptor)
for (capturedParamDesc in info.allRecapturedParameters) {
if (capturedParamDesc.fieldName == THIS && isContinuationCreate) {
+33
View File
@@ -0,0 +1,33 @@
// WITH_RUNTIME
// WITH_COROUTINES
import helpers.*
import kotlin.coroutines.experimental.*
interface Consumer { fun consume(s: String) }
inline fun crossInlineBuilder(crossinline block: (String) -> Unit) = object : Consumer {
override fun consume(s: String) {
block(s)
}
}
fun builder(block: suspend Unit.() -> Unit) {
block.startCoroutine(Unit, EmptyContinuation)
}
class Container {
var y: String = "FAIL"
val consumer = crossInlineBuilder { s ->
builder {
y = s
}
}
}
fun box(): String {
val container = Container()
container.consumer.consume("OK")
return container.y
}
@@ -5930,6 +5930,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
doTest(fileName);
}
@TestMetadata("kt21605.kt")
public void testKt21605() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/kt21605.kt");
doTest(fileName);
}
@TestMetadata("lastExpressionIsLoop.kt")
public void testLastExpressionIsLoop() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/lastExpressionIsLoop.kt");
@@ -5930,6 +5930,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
doTest(fileName);
}
@TestMetadata("kt21605.kt")
public void testKt21605() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/kt21605.kt");
doTest(fileName);
}
@TestMetadata("lastExpressionIsLoop.kt")
public void testLastExpressionIsLoop() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/lastExpressionIsLoop.kt");
@@ -5930,6 +5930,12 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
doTest(fileName);
}
@TestMetadata("kt21605.kt")
public void testKt21605() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/kt21605.kt");
doTest(fileName);
}
@TestMetadata("lastExpressionIsLoop.kt")
public void testLastExpressionIsLoop() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/lastExpressionIsLoop.kt");
@@ -7249,6 +7249,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
doTest(fileName);
}
@TestMetadata("kt21605.kt")
public void testKt21605() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/kt21605.kt");
doTest(fileName);
}
@TestMetadata("lastExpressionIsLoop.kt")
public void testLastExpressionIsLoop() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/lastExpressionIsLoop.kt");