diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/AddContinuationLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/AddContinuationLowering.kt index b659860166a..db90f0473e4 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/AddContinuationLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/AddContinuationLowering.kt @@ -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) } diff --git a/compiler/testData/codegen/box/coroutines/bridges/lambdaWithLongReceiver_ir.txt b/compiler/testData/codegen/box/coroutines/bridges/lambdaWithLongReceiver_ir.txt index c8f7bc41449..8bc554b8b3b 100644 --- a/compiler/testData/codegen/box/coroutines/bridges/lambdaWithLongReceiver_ir.txt +++ b/compiler/testData/codegen/box/coroutines/bridges/lambdaWithLongReceiver_ir.txt @@ -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 (p0: kotlin.coroutines.Continuation): void diff --git a/compiler/testData/codegen/box/coroutines/stopAfter.kt b/compiler/testData/codegen/box/coroutines/stopAfter.kt new file mode 100644 index 00000000000..1737d52435a --- /dev/null +++ b/compiler/testData/codegen/box/coroutines/stopAfter.kt @@ -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 Iterator.stopAfter(crossinline predicate: (T) -> Boolean): Iterator = iterator { + for (element in this@stopAfter) { + yield(element) + if (predicate(element)) { + break + } + } +} + +fun box() = + listOf("OK", "fail").iterator().stopAfter { it == "OK" }.next() diff --git a/compiler/testData/codegen/boxInline/suspend/receiver/inlineOrdinaryOfNoinlineSuspend.kt b/compiler/testData/codegen/boxInline/suspend/receiver/inlineOrdinaryOfNoinlineSuspend.kt index 62c608bd405..9e65cc7e552 100644 --- a/compiler/testData/codegen/boxInline/suspend/receiver/inlineOrdinaryOfNoinlineSuspend.kt +++ b/compiler/testData/codegen/boxInline/suspend/receiver/inlineOrdinaryOfNoinlineSuspend.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_MULTI_MODULE: JVM_IR // FILE: test.kt // COMMON_COROUTINES_TEST // WITH_RUNTIME diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index cfec674664f..a48967fbf0b 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -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"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index b3dce28991f..d82a114823b 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -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"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java index 0cbe3e088c5..3569bc06828 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java @@ -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"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 757dd98ec87..7582b6585f8 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -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"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java index 99d57ed9dc7..221dfe0dee2 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java @@ -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"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index 0e6c619b1f2..665a6397c0d 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -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");