Force boxing kotlin.Result return type of suspend functions

#KT-40843 Fixed
This commit is contained in:
Ilmir Usmanov
2020-08-10 15:39:04 +02:00
parent b06218c456
commit 00bf07fc41
9 changed files with 69 additions and 4 deletions
@@ -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
}
@@ -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")
@@ -0,0 +1,28 @@
// WITH_RUNTIME
// WITH_COROUTINES
import helpers.*
import kotlin.coroutines.*
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
var continuation: Continuation<Unit>? = null
suspend fun suspendMe() = suspendCoroutine<Unit> { continuation = it }
@Suppress("RESULT_CLASS_IN_RETURN_TYPE")
suspend fun signInFlowStepFirst(): Result<Unit> = try {
Result.success(suspendMe())
} catch (e: Exception) {
Result.failure(e)
}
fun box(): String {
builder {
signInFlowStepFirst()
}
continuation!!.resumeWithException(Exception("BOOYA"))
return "OK"
}
@@ -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")
@@ -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")
@@ -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")
@@ -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")
@@ -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")
@@ -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")