JVM_IR: fix name of received field for suspend lambdas

$ at the start caused AnonymousObjectTransformer to skip the field.
This commit is contained in:
Georgy Bronnikov
2019-12-21 15:26:16 +03:00
committed by Ilmir Usmanov
parent 068d3f4beb
commit d4b0151f51
10 changed files with 58 additions and 3 deletions
@@ -110,7 +110,8 @@ private class AddContinuationLowering(private val context: JvmBackendContext) :
val receiverField = info.function.extensionReceiverParameter?.let {
assert(info.arity != 0)
addField("\$p", it.type)
// Do not put '$' at the start, to avoid being caught by inlineCodegenUtils.isCapturedFieldName()
addField("p\$", it.type)
}
val parametersFields = info.function.valueParameters.map { addField(it.name.asString(), it.type) }
@@ -1,8 +1,8 @@
@kotlin.coroutines.jvm.internal.DebugMetadata
@kotlin.Metadata
final class LambdaWithLongReceiverKt$box$1$1 {
private field $p: long
private field label: int
private field p$: long
inner class LambdaWithLongReceiverKt$box$1
inner class LambdaWithLongReceiverKt$box$1$1
public method <init>(p0: kotlin.coroutines.Continuation): void
+25
View File
@@ -0,0 +1,25 @@
// IGNORE_BACKEND_FIR: JVM_IR
// WITH_RUNTIME
/**
* _Example_
* The following will print `1`, `2` and `3` when executed:
* ```
* arrayOf(1, 2, 3, 4, 5)
* .iterator()
* .stopAfter { it == 3 }
* .forEach(::println)
* ```
* @return an iterator, which stops [this] Iterator after first element for which [predicate] returns `true`
*/
inline fun <T> Iterator<T>.stopAfter(crossinline predicate: (T) -> Boolean): Iterator<T> = iterator {
for (element in this@stopAfter) {
yield(element)
if (predicate(element)) {
break
}
}
}
fun box() =
listOf("OK", "fail").iterator().stopAfter { it == "OK" }.next()
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_MULTI_MODULE: JVM_IR
// FILE: test.kt
// COMMON_COROUTINES_TEST
// WITH_RUNTIME
@@ -6539,6 +6539,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/statementLikeLastExpression.kt", "kotlin.coroutines");
}
@TestMetadata("stopAfter.kt")
public void testStopAfter() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/stopAfter.kt");
}
@TestMetadata("suspendCallsInArguments.kt")
public void testSuspendCallsInArguments_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/suspendCallsInArguments.kt", "kotlin.coroutines.experimental");
@@ -6539,6 +6539,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/statementLikeLastExpression.kt", "kotlin.coroutines");
}
@TestMetadata("stopAfter.kt")
public void testStopAfter() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/stopAfter.kt");
}
@TestMetadata("suspendCallsInArguments.kt")
public void testSuspendCallsInArguments_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/suspendCallsInArguments.kt", "kotlin.coroutines.experimental");
@@ -6179,6 +6179,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/statementLikeLastExpression.kt", "kotlin.coroutines");
}
@TestMetadata("stopAfter.kt")
public void testStopAfter() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/stopAfter.kt");
}
@TestMetadata("suspendCallsInArguments.kt")
public void testSuspendCallsInArguments_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/suspendCallsInArguments.kt", "kotlin.coroutines");
@@ -6179,6 +6179,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/statementLikeLastExpression.kt", "kotlin.coroutines");
}
@TestMetadata("stopAfter.kt")
public void testStopAfter() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/stopAfter.kt");
}
@TestMetadata("suspendCallsInArguments.kt")
public void testSuspendCallsInArguments_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/suspendCallsInArguments.kt", "kotlin.coroutines");
@@ -5269,6 +5269,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/statementLikeLastExpression.kt", "kotlin.coroutines");
}
@TestMetadata("stopAfter.kt")
public void testStopAfter() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/stopAfter.kt");
}
@TestMetadata("suspendCallsInArguments.kt")
public void testSuspendCallsInArguments_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/suspendCallsInArguments.kt", "kotlin.coroutines");
@@ -5589,6 +5589,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/statementLikeLastExpression.kt", "kotlin.coroutines");
}
@TestMetadata("stopAfter.kt")
public void testStopAfter() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/stopAfter.kt");
}
@TestMetadata("suspendCallsInArguments.kt")
public void testSuspendCallsInArguments_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/suspendCallsInArguments.kt", "kotlin.coroutines.experimental");