diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/KotlinTypeMapper.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/KotlinTypeMapper.kt index 9b02e095d76..e8c028913ae 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/KotlinTypeMapper.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/KotlinTypeMapper.kt @@ -52,10 +52,7 @@ import org.jetbrains.kotlin.resolve.bindingContextUtil.isUsedAsExpression import org.jetbrains.kotlin.resolve.calls.model.DefaultValueArgument import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall import org.jetbrains.kotlin.resolve.calls.model.VarargValueArgument -import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns -import org.jetbrains.kotlin.resolve.descriptorUtil.classId -import org.jetbrains.kotlin.resolve.descriptorUtil.isPublishedApi -import org.jetbrains.kotlin.resolve.descriptorUtil.module +import org.jetbrains.kotlin.resolve.descriptorUtil.* import org.jetbrains.kotlin.resolve.jvm.AsmTypes.DEFAULT_CONSTRUCTOR_MARKER import org.jetbrains.kotlin.resolve.jvm.AsmTypes.OBJECT_TYPE import org.jetbrains.kotlin.resolve.jvm.JvmClassName @@ -385,6 +382,11 @@ class KotlinTypeMapper @JvmOverloads constructor( return functionDescriptor.builtIns.nullableAnyType } + // Force boxing for Result type, otherwise, the coroutines machinery will break + if (originalReturnType.constructor.declarationDescriptor?.fqNameSafe == RESULT_FQ_NAME) { + return functionDescriptor.builtIns.nullableAnyType + } + // Don't box other inline classes return originalReturnType } diff --git a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java index a3aeab570b6..dabdf90aeea 100644 --- a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java @@ -7517,6 +7517,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT public void testOverrideSuspendFun_Int_1_3() throws Exception { runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/inlineClasses/overrideSuspendFun_Int.kt", "kotlin.coroutines"); } + + @TestMetadata("returnResult.kt") + public void testReturnResult() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/inlineClasses/returnResult.kt"); + } } @TestMetadata("compiler/testData/codegen/box/coroutines/intLikeVarSpilling") diff --git a/compiler/testData/codegen/box/coroutines/inlineClasses/returnResult.kt b/compiler/testData/codegen/box/coroutines/inlineClasses/returnResult.kt new file mode 100644 index 00000000000..b97f8509663 --- /dev/null +++ b/compiler/testData/codegen/box/coroutines/inlineClasses/returnResult.kt @@ -0,0 +1,28 @@ +// WITH_RUNTIME +// WITH_COROUTINES + +import helpers.* +import kotlin.coroutines.* + +fun builder(c: suspend () -> Unit) { + c.startCoroutine(EmptyContinuation) +} + +var continuation: Continuation? = null + +suspend fun suspendMe() = suspendCoroutine { continuation = it } + +@Suppress("RESULT_CLASS_IN_RETURN_TYPE") +suspend fun signInFlowStepFirst(): Result = try { + Result.success(suspendMe()) +} catch (e: Exception) { + Result.failure(e) +} + +fun box(): String { + builder { + signInFlowStepFirst() + } + continuation!!.resumeWithException(Exception("BOOYA")) + return "OK" +} diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 49d75b8e107..f2026a05ad6 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -8312,6 +8312,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { public void testOverrideSuspendFun_Int_1_3() throws Exception { runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/inlineClasses/overrideSuspendFun_Int.kt", "kotlin.coroutines"); } + + @TestMetadata("returnResult.kt") + public void testReturnResult() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/inlineClasses/returnResult.kt"); + } } @TestMetadata("compiler/testData/codegen/box/coroutines/intLikeVarSpilling") diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 17b12c6a9e7..4e553f9cb2c 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -8312,6 +8312,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes public void testOverrideSuspendFun_Int_1_3() throws Exception { runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/inlineClasses/overrideSuspendFun_Int.kt", "kotlin.coroutines"); } + + @TestMetadata("returnResult.kt") + public void testReturnResult() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/inlineClasses/returnResult.kt"); + } } @TestMetadata("compiler/testData/codegen/box/coroutines/intLikeVarSpilling") diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 643beaf3084..467882ce3b5 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -7517,6 +7517,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes public void testOverrideSuspendFun_Int_1_3() throws Exception { runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/inlineClasses/overrideSuspendFun_Int.kt", "kotlin.coroutines"); } + + @TestMetadata("returnResult.kt") + public void testReturnResult() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/inlineClasses/returnResult.kt"); + } } @TestMetadata("compiler/testData/codegen/box/coroutines/intLikeVarSpilling") diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java index 2767b3853cd..af7ec258d8b 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java @@ -6407,6 +6407,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes public void testOverrideSuspendFun_Int_1_3() throws Exception { runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/inlineClasses/overrideSuspendFun_Int.kt", "kotlin.coroutines"); } + + @TestMetadata("returnResult.kt") + public void testReturnResult() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/inlineClasses/returnResult.kt"); + } } @TestMetadata("compiler/testData/codegen/box/coroutines/intLikeVarSpilling") 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 3e5431bc7cb..4c4ba8c4223 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 @@ -6407,6 +6407,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { public void testOverrideSuspendFun_Int_1_3() throws Exception { runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/inlineClasses/overrideSuspendFun_Int.kt", "kotlin.coroutines"); } + + @TestMetadata("returnResult.kt") + public void testReturnResult() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/inlineClasses/returnResult.kt"); + } } @TestMetadata("compiler/testData/codegen/box/coroutines/intLikeVarSpilling") 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 f655f270c86..b714de2082a 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 @@ -6407,6 +6407,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { public void testOverrideSuspendFun_Int_1_3() throws Exception { runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/inlineClasses/overrideSuspendFun_Int.kt", "kotlin.coroutines"); } + + @TestMetadata("returnResult.kt") + public void testReturnResult() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/inlineClasses/returnResult.kt"); + } } @TestMetadata("compiler/testData/codegen/box/coroutines/intLikeVarSpilling")