diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/coroutineCodegenUtil.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/coroutineCodegenUtil.kt index a37332b8e43..749a5e86f91 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/coroutineCodegenUtil.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/coroutineCodegenUtil.kt @@ -475,7 +475,8 @@ fun FunctionDescriptor.originalReturnTypeOfSuspendFunctionReturningUnboxedInline // Force boxing if the function overrides function with different type modulo nullability if (originalDescriptor.overriddenDescriptors.any { (it.original.returnType?.isMarkedNullable == true && it.original.returnType?.isNullableUnderlyingType() == true) || - it.original.returnType?.makeNotNullable() != originalReturnType.makeNotNullable() + // We do not care about type parameters, just main class type + it.original.returnType?.constructor?.declarationDescriptor != originalReturnType.constructor.declarationDescriptor }) return null // 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 003bfa55e10..9ecb79b7683 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 @@ -8749,6 +8749,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/coroutines/tailCallOptimizations/interfaceDelegation.kt"); } + @TestMetadata("returnInlineClass.kt") + public void testReturnInlineClass() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/tailCallOptimizations/returnInlineClass.kt"); + } + @TestMetadata("simple.kt") public void testSimple() throws Exception { runTest("compiler/testData/codegen/box/coroutines/tailCallOptimizations/simple.kt"); diff --git a/compiler/testData/codegen/box/coroutines/tailCallOptimizations/returnInlineClass.kt b/compiler/testData/codegen/box/coroutines/tailCallOptimizations/returnInlineClass.kt new file mode 100644 index 00000000000..0b866270620 --- /dev/null +++ b/compiler/testData/codegen/box/coroutines/tailCallOptimizations/returnInlineClass.kt @@ -0,0 +1,41 @@ +// TARGET_BACKEND: JVM +// IGNORE_BACKEND: JVM_IR +// IGNORE_BACKEND_FIR: JVM_IR +// FULL_JDK +// WITH_RUNTIME +// WITH_COROUTINES +// CHECK_TAIL_CALL_OPTIMIZATION + +import helpers.* +import kotlin.coroutines.* + +public inline class ValueOrClosed(val holder: Any?) + +public interface Channel { + public suspend fun receiveOrClosed(): ValueOrClosed +} + +class AbstractChannel : Channel { + private suspend fun receiveSuspend(): R { + TailCallOptimizationChecker.saveStackTrace() + return ValueOrClosed("OK") as R + } + + public final override suspend fun receiveOrClosed(): ValueOrClosed { + return receiveSuspend() + } +} + +fun builder(c: suspend () -> Unit) { + c.startCoroutine(EmptyContinuation) +} + +fun box(): String { + var res = "FAIL" + builder { + val channel: Channel = AbstractChannel() + res = channel.receiveOrClosed().holder as String + } + TailCallOptimizationChecker.checkStateMachineIn("receiveOrClosed-v5DwqjU") + return res +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 48f8593d1a0..c91ab5a5bee 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -10079,6 +10079,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/coroutines/tailCallOptimizations/interfaceDelegation.kt"); } + @TestMetadata("returnInlineClass.kt") + public void testReturnInlineClass() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/tailCallOptimizations/returnInlineClass.kt"); + } + @TestMetadata("simple.kt") public void testSimple() throws Exception { runTest("compiler/testData/codegen/box/coroutines/tailCallOptimizations/simple.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 6e56bb5a607..691a5928d52 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -10079,6 +10079,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/coroutines/tailCallOptimizations/interfaceDelegation.kt"); } + @TestMetadata("returnInlineClass.kt") + public void testReturnInlineClass() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/tailCallOptimizations/returnInlineClass.kt"); + } + @TestMetadata("simple.kt") public void testSimple() throws Exception { runTest("compiler/testData/codegen/box/coroutines/tailCallOptimizations/simple.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index d9725b94556..41bd8030c2c 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -8749,6 +8749,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/coroutines/tailCallOptimizations/interfaceDelegation.kt"); } + @TestMetadata("returnInlineClass.kt") + public void testReturnInlineClass() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/tailCallOptimizations/returnInlineClass.kt"); + } + @TestMetadata("simple.kt") public void testSimple() throws Exception { runTest("compiler/testData/codegen/box/coroutines/tailCallOptimizations/simple.kt"); 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 1d9b1f8af2d..dfef036fbf2 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 @@ -21414,11 +21414,6 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/ranges/unsigned/expression/emptyRange.kt"); } - @TestMetadata("inexactDownToMinValue.kt") - public void testInexactDownToMinValue() throws Exception { - runTest("compiler/testData/codegen/box/ranges/unsigned/expression/inexactDownToMinValue.kt"); - } - @TestMetadata("inexactSteppedDownTo.kt") public void testInexactSteppedDownTo() throws Exception { runTest("compiler/testData/codegen/box/ranges/unsigned/expression/inexactSteppedDownTo.kt"); @@ -21464,21 +21459,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/ranges/unsigned/expression/openRange.kt"); } - @TestMetadata("overflowZeroDownToMaxValue.kt") - public void testOverflowZeroDownToMaxValue() throws Exception { - runTest("compiler/testData/codegen/box/ranges/unsigned/expression/overflowZeroDownToMaxValue.kt"); - } - @TestMetadata("overflowZeroToMinValue.kt") public void testOverflowZeroToMinValue() throws Exception { runTest("compiler/testData/codegen/box/ranges/unsigned/expression/overflowZeroToMinValue.kt"); } - @TestMetadata("progressionDownToMinValue.kt") - public void testProgressionDownToMinValue() throws Exception { - runTest("compiler/testData/codegen/box/ranges/unsigned/expression/progressionDownToMinValue.kt"); - } - @TestMetadata("progressionMaxValueMinusTwoToMaxValue.kt") public void testProgressionMaxValueMinusTwoToMaxValue() throws Exception { runTest("compiler/testData/codegen/box/ranges/unsigned/expression/progressionMaxValueMinusTwoToMaxValue.kt");