From 819d64a2ef9b36b2ea27bfb0d4edda10b9cf3060 Mon Sep 17 00:00:00 2001 From: Ilmir Usmanov Date: Fri, 16 Oct 2020 18:22:13 +0200 Subject: [PATCH] Box inline class returned from suspend lambda non-locally in JVM_IR #KT-41194 Fixed --- .../jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt | 4 ++++ .../codegen/box/coroutines/inlineClasses/nonLocalReturn.kt | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt index bd461c949c8..c9ed1bfcc97 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt @@ -827,6 +827,10 @@ class ExpressionCodegen( } val afterReturnLabel = Label() expression.value.accept(this, data).materializeAt(returnType, returnIrType) + // In case of non-local return from suspend lambda 'materializeAt' does not box return value, box it manually. + if (isNonLocalReturn && owner.isInvokeSuspendOfLambda() && expression.value.type.isKotlinResult()) { + StackValue.boxInlineClass(expression.value.type.toIrBasedKotlinType(), mv) + } generateFinallyBlocksIfNeeded(returnType, afterReturnLabel, data) expression.markLineNumber(startOffset = true) if (isNonLocalReturn) { diff --git a/compiler/testData/codegen/box/coroutines/inlineClasses/nonLocalReturn.kt b/compiler/testData/codegen/box/coroutines/inlineClasses/nonLocalReturn.kt index 6e2915ca13b..5554e8b9d75 100644 --- a/compiler/testData/codegen/box/coroutines/inlineClasses/nonLocalReturn.kt +++ b/compiler/testData/codegen/box/coroutines/inlineClasses/nonLocalReturn.kt @@ -1,6 +1,5 @@ // WITH_RUNTIME -// IGNORE_BACKEND: JVM_IR, JS_IR -// IGNORE_BACKEND_FIR: JVM_IR +// IGNORE_BACKEND: JS_IR import kotlin.coroutines.*