diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java index cfb34ee8155..17bce302afb 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java @@ -17684,6 +17684,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/funInterface/result.kt"); } + @Test + @TestMetadata("resultAny.kt") + public void testResultAny() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/funInterface/resultAny.kt"); + } + @Test @TestMetadata("string.kt") public void testString() throws Exception { @@ -17736,6 +17742,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/lambda/result.kt"); } + @Test + @TestMetadata("resultAny.kt") + public void testResultAny() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/lambda/resultAny.kt"); + } + @Test @TestMetadata("string.kt") public void testString() throws Exception { @@ -17788,6 +17800,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/objectLiteral/result.kt"); } + @Test + @TestMetadata("resultAny.kt") + public void testResultAny() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/objectLiteral/resultAny.kt"); + } + @Test @TestMetadata("string.kt") public void testString() throws Exception { 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 4456f37dbf6..67d2bdb3462 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 @@ -626,6 +626,7 @@ class ExpressionCodegen( // bridge to unbox it. Instead, we unbox it in the non-mangled function manually. private fun unboxResultIfNeeded(arg: IrGetValue) { if (arg.type.erasedUpperBound.fqNameWhenAvailable != StandardNames.RESULT_FQ_NAME) return + if (!onlyResultInlineClassParameters()) return if (irFunction !is IrSimpleFunction) return // Skip Result's methods if (irFunction.parentAsClass.fqNameWhenAvailable == StandardNames.RESULT_FQ_NAME) return @@ -642,6 +643,10 @@ class ExpressionCodegen( StackValue.unboxInlineClass(OBJECT_TYPE, arg.type.erasedUpperBound.defaultType.toIrBasedKotlinType(), mv) } + private fun onlyResultInlineClassParameters(): Boolean = irFunction.valueParameters.all { + !it.type.erasedUpperBound.isInline || it.type.erasedUpperBound.fqNameWhenAvailable == StandardNames.RESULT_FQ_NAME + } + private fun hasBridge(): Boolean = irFunction.parentAsClass.declarations.any { function -> function is IrFunction && function != irFunction && context.methodSignatureMapper.mapSignatureSkipGeneric(function).let { diff --git a/compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/funInterface/resultAny.kt b/compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/funInterface/resultAny.kt new file mode 100644 index 00000000000..f58537aab59 --- /dev/null +++ b/compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/funInterface/resultAny.kt @@ -0,0 +1,22 @@ +// DONT_TARGET_EXACT_BACKEND: WASM +// WASM_MUTE_REASON: SAM_CONVERSIONS +// !LANGUAGE: +InlineClasses +// WITH_RUNTIME + +inline class IC(val value: Any) + +fun foo(a: Result, ic: IC): Pair = bar(a, ic) { a, ic -> + a.getOrThrow() to ic.value +} + +fun interface FunIFace { + fun call(t1: T1, t2: T2): R +} + +fun bar(t1: T1, t2: T2, f: FunIFace): R { + return f.call(t1, t2) +} + +fun Pair.join(): String = "$first$second" + +fun box(): String = foo(Result.success("O"), IC("K")).join() \ No newline at end of file diff --git a/compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/lambda/resultAny.kt b/compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/lambda/resultAny.kt new file mode 100644 index 00000000000..7743341b618 --- /dev/null +++ b/compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/lambda/resultAny.kt @@ -0,0 +1,16 @@ +// !LANGUAGE: +InlineClasses +// WITH_RUNTIME + +inline class IC(val value: Any) + +fun foo(a: Result, ic: IC): Pair = bar(a, ic) { a, ic -> + a.getOrThrow() to ic.value +} + +fun bar(t1: T1, t2: T2, f: (T1, T2) -> R): R { + return f(t1, t2) +} + +fun Pair.join(): String = "$first$second" + +fun box(): String = foo(Result.success("O"), IC("K")).join() \ No newline at end of file diff --git a/compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/objectLiteral/resultAny.kt b/compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/objectLiteral/resultAny.kt new file mode 100644 index 00000000000..07c6d7404e6 --- /dev/null +++ b/compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/objectLiteral/resultAny.kt @@ -0,0 +1,20 @@ +// !LANGUAGE: +InlineClasses +// WITH_RUNTIME + +inline class IC(val value: Any) + +fun foo(a: Result, ic: IC): Pair = bar(a, ic, object : IFace, IC, Pair> { + override fun call(a: Result, ic: IC): Pair = a.getOrThrow() to ic.value +}) + +interface IFace { + fun call(t1: T1, t2: T2): R +} + +fun bar(t1: T1, t2: T2, f: IFace): R { + return f.call(t1, t2) +} + +fun Pair.join(): String = "$first$second" + +fun box(): String = foo(Result.success("O"), IC("K")).join() \ No newline at end of file diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java index 05b37087af6..0961403bd71 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java @@ -17684,6 +17684,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/funInterface/result.kt"); } + @Test + @TestMetadata("resultAny.kt") + public void testResultAny() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/funInterface/resultAny.kt"); + } + @Test @TestMetadata("string.kt") public void testString() throws Exception { @@ -17736,6 +17742,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/lambda/result.kt"); } + @Test + @TestMetadata("resultAny.kt") + public void testResultAny() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/lambda/resultAny.kt"); + } + @Test @TestMetadata("string.kt") public void testString() throws Exception { @@ -17788,6 +17800,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/objectLiteral/result.kt"); } + @Test + @TestMetadata("resultAny.kt") + public void testResultAny() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/objectLiteral/resultAny.kt"); + } + @Test @TestMetadata("string.kt") public void testString() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java index 7b04d136da1..2c7e979804b 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java @@ -17684,6 +17684,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/funInterface/result.kt"); } + @Test + @TestMetadata("resultAny.kt") + public void testResultAny() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/funInterface/resultAny.kt"); + } + @Test @TestMetadata("string.kt") public void testString() throws Exception { @@ -17736,6 +17742,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/lambda/result.kt"); } + @Test + @TestMetadata("resultAny.kt") + public void testResultAny() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/lambda/resultAny.kt"); + } + @Test @TestMetadata("string.kt") public void testString() throws Exception { @@ -17788,6 +17800,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/objectLiteral/result.kt"); } + @Test + @TestMetadata("resultAny.kt") + public void testResultAny() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/objectLiteral/resultAny.kt"); + } + @Test @TestMetadata("string.kt") public void testString() throws Exception { diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 8e2ffa8dc16..e572900f046 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -15492,6 +15492,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/funInterface/result.kt"); } + @TestMetadata("resultAny.kt") + public void testResultAny() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/funInterface/resultAny.kt"); + } + @TestMetadata("string.kt") public void testString() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/funInterface/string.kt"); @@ -15540,6 +15545,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/lambda/result.kt"); } + @TestMetadata("resultAny.kt") + public void testResultAny() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/lambda/resultAny.kt"); + } + @TestMetadata("string.kt") public void testString() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/lambda/string.kt"); @@ -15588,6 +15598,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/objectLiteral/result.kt"); } + @TestMetadata("resultAny.kt") + public void testResultAny() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/objectLiteral/resultAny.kt"); + } + @TestMetadata("string.kt") public void testString() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/objectLiteral/string.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java index ac716696f64..fb684cfdbdf 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java @@ -13342,6 +13342,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/funInterface/result.kt"); } + @TestMetadata("resultAny.kt") + public void testResultAny() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/funInterface/resultAny.kt"); + } + @TestMetadata("string.kt") public void testString() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/funInterface/string.kt"); @@ -13390,6 +13395,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/lambda/result.kt"); } + @TestMetadata("resultAny.kt") + public void testResultAny() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/lambda/resultAny.kt"); + } + @TestMetadata("string.kt") public void testString() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/lambda/string.kt"); @@ -13438,6 +13448,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/objectLiteral/result.kt"); } + @TestMetadata("resultAny.kt") + public void testResultAny() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/objectLiteral/resultAny.kt"); + } + @TestMetadata("string.kt") public void testString() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/objectLiteral/string.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java index ee7f3c8c69a..3e25c2bbef6 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java @@ -13342,6 +13342,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/funInterface/result.kt"); } + @TestMetadata("resultAny.kt") + public void testResultAny() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/funInterface/resultAny.kt"); + } + @TestMetadata("string.kt") public void testString() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/funInterface/string.kt"); @@ -13390,6 +13395,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/lambda/result.kt"); } + @TestMetadata("resultAny.kt") + public void testResultAny() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/lambda/resultAny.kt"); + } + @TestMetadata("string.kt") public void testString() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/lambda/string.kt"); @@ -13438,6 +13448,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/objectLiteral/result.kt"); } + @TestMetadata("resultAny.kt") + public void testResultAny() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/objectLiteral/resultAny.kt"); + } + @TestMetadata("string.kt") public void testString() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/objectLiteral/string.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index 4e954e3625b..b44695e942a 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -13407,6 +13407,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/funInterface/result.kt"); } + @TestMetadata("resultAny.kt") + public void testResultAny() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/funInterface/resultAny.kt"); + } + @TestMetadata("string.kt") public void testString() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/funInterface/string.kt"); @@ -13455,6 +13460,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/lambda/result.kt"); } + @TestMetadata("resultAny.kt") + public void testResultAny() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/lambda/resultAny.kt"); + } + @TestMetadata("string.kt") public void testString() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/lambda/string.kt"); @@ -13503,6 +13513,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/objectLiteral/result.kt"); } + @TestMetadata("resultAny.kt") + public void testResultAny() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/objectLiteral/resultAny.kt"); + } + @TestMetadata("string.kt") public void testString() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/objectLiteral/string.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java index c31ba15face..ad33bfcffb5 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java @@ -7591,6 +7591,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/lambda/result.kt"); } + @TestMetadata("resultAny.kt") + public void testResultAny() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/lambda/resultAny.kt"); + } + @TestMetadata("string.kt") public void testString() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/lambda/string.kt"); @@ -7639,6 +7644,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/objectLiteral/result.kt"); } + @TestMetadata("resultAny.kt") + public void testResultAny() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/objectLiteral/resultAny.kt"); + } + @TestMetadata("string.kt") public void testString() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter/objectLiteral/string.kt");