Force boxing kotlin.Result return type of suspend functions
#KT-40843 Fixed
This commit is contained in:
@@ -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.DefaultValueArgument
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.VarargValueArgument
|
import org.jetbrains.kotlin.resolve.calls.model.VarargValueArgument
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
import org.jetbrains.kotlin.resolve.descriptorUtil.*
|
||||||
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.jvm.AsmTypes.DEFAULT_CONSTRUCTOR_MARKER
|
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.AsmTypes.OBJECT_TYPE
|
||||||
import org.jetbrains.kotlin.resolve.jvm.JvmClassName
|
import org.jetbrains.kotlin.resolve.jvm.JvmClassName
|
||||||
@@ -385,6 +382,11 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
|||||||
return functionDescriptor.builtIns.nullableAnyType
|
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
|
// Don't box other inline classes
|
||||||
return originalReturnType
|
return originalReturnType
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
+5
@@ -7517,6 +7517,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
|||||||
public void testOverrideSuspendFun_Int_1_3() throws Exception {
|
public void testOverrideSuspendFun_Int_1_3() throws Exception {
|
||||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/inlineClasses/overrideSuspendFun_Int.kt", "kotlin.coroutines");
|
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")
|
@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"
|
||||||
|
}
|
||||||
+5
@@ -8312,6 +8312,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
public void testOverrideSuspendFun_Int_1_3() throws Exception {
|
public void testOverrideSuspendFun_Int_1_3() throws Exception {
|
||||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/inlineClasses/overrideSuspendFun_Int.kt", "kotlin.coroutines");
|
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")
|
@TestMetadata("compiler/testData/codegen/box/coroutines/intLikeVarSpilling")
|
||||||
|
|||||||
+5
@@ -8312,6 +8312,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
public void testOverrideSuspendFun_Int_1_3() throws Exception {
|
public void testOverrideSuspendFun_Int_1_3() throws Exception {
|
||||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/inlineClasses/overrideSuspendFun_Int.kt", "kotlin.coroutines");
|
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")
|
@TestMetadata("compiler/testData/codegen/box/coroutines/intLikeVarSpilling")
|
||||||
|
|||||||
+5
@@ -7517,6 +7517,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
public void testOverrideSuspendFun_Int_1_3() throws Exception {
|
public void testOverrideSuspendFun_Int_1_3() throws Exception {
|
||||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/inlineClasses/overrideSuspendFun_Int.kt", "kotlin.coroutines");
|
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")
|
@TestMetadata("compiler/testData/codegen/box/coroutines/intLikeVarSpilling")
|
||||||
|
|||||||
Generated
+5
@@ -6407,6 +6407,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
|
|||||||
public void testOverrideSuspendFun_Int_1_3() throws Exception {
|
public void testOverrideSuspendFun_Int_1_3() throws Exception {
|
||||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/inlineClasses/overrideSuspendFun_Int.kt", "kotlin.coroutines");
|
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")
|
@TestMetadata("compiler/testData/codegen/box/coroutines/intLikeVarSpilling")
|
||||||
|
|||||||
Generated
+5
@@ -6407,6 +6407,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
|||||||
public void testOverrideSuspendFun_Int_1_3() throws Exception {
|
public void testOverrideSuspendFun_Int_1_3() throws Exception {
|
||||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/inlineClasses/overrideSuspendFun_Int.kt", "kotlin.coroutines");
|
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")
|
@TestMetadata("compiler/testData/codegen/box/coroutines/intLikeVarSpilling")
|
||||||
|
|||||||
+5
@@ -6407,6 +6407,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
|||||||
public void testOverrideSuspendFun_Int_1_3() throws Exception {
|
public void testOverrideSuspendFun_Int_1_3() throws Exception {
|
||||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/inlineClasses/overrideSuspendFun_Int.kt", "kotlin.coroutines");
|
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")
|
@TestMetadata("compiler/testData/codegen/box/coroutines/intLikeVarSpilling")
|
||||||
|
|||||||
Reference in New Issue
Block a user