diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java index a356bcfb615..43790f2323f 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java @@ -22109,6 +22109,18 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT public void testLambdaTakesResultThroughBridge() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/result/lambdaTakesResultThroughBridge.kt"); } + + @Test + @TestMetadata("returnGenericMultiModule.kt") + public void testReturnGenericMultiModule() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/result/returnGenericMultiModule.kt"); + } + + @Test + @TestMetadata("returnGenericSingleModule.kt") + public void testReturnGenericSingleModule() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/result/returnGenericSingleModule.kt"); + } } @Nested diff --git a/compiler/ir/backend.jvm/codegen/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt b/compiler/ir/backend.jvm/codegen/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt index a9aa8c46c91..ca5dbc11549 100644 --- a/compiler/ir/backend.jvm/codegen/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt +++ b/compiler/ir/backend.jvm/codegen/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt @@ -694,13 +694,11 @@ class ExpressionCodegen( // Otherwise, we need to treat `Result` as boxed if it overrides a non-`Result` or boxed `Result` type. // TODO: if results of `needsResultArgumentUnboxing` for `overriddenSymbols` are inconsistent, the boxedness // of the `Result` depends on which overridden function is called. This is probably unfixable. + val signature = methodSignatureMapper.mapAsmMethod(this) val parent = this.parent return parent is IrClass && - parent.functions.none { - it != this && it.origin == IrDeclarationOrigin.BRIDGE && it.attributeOwnerId == attributeOwnerId - } && overriddenSymbols.any { - it.owner.resultIsActuallyAny(index) != false + methodSignatureMapper.mapAsmMethod(it.owner) == signature && it.owner.resultIsActuallyAny(index) != false } } diff --git a/compiler/testData/codegen/box/inlineClasses/result/returnGenericMultiModule.kt b/compiler/testData/codegen/box/inlineClasses/result/returnGenericMultiModule.kt new file mode 100644 index 00000000000..d5511ff4d07 --- /dev/null +++ b/compiler/testData/codegen/box/inlineClasses/result/returnGenericMultiModule.kt @@ -0,0 +1,21 @@ +// WITH_STDLIB + +// MODULE: lib +// FILE: lib.kt +interface Operation { + fun performOperation(): T +} + +object ResultOperation : Operation> { + override fun performOperation(): Result { + return Result.success(1) + } +} + +// MODULE: main(lib) +// FILE: main.kt +fun box(): String { + val x = ResultOperation.performOperation() + if ("$x" != "Success(1)") return "$x" + return "OK" +} diff --git a/compiler/testData/codegen/box/inlineClasses/result/returnGenericSingleModule.kt b/compiler/testData/codegen/box/inlineClasses/result/returnGenericSingleModule.kt new file mode 100644 index 00000000000..e2b772cefeb --- /dev/null +++ b/compiler/testData/codegen/box/inlineClasses/result/returnGenericSingleModule.kt @@ -0,0 +1,19 @@ +// WITH_STDLIB + +// FILE: lib.kt +interface Operation { + fun performOperation(): T +} + +object ResultOperation : Operation> { + override fun performOperation(): Result { + return Result.success(1) + } +} + +// FILE: main.kt +fun box(): String { + val x = ResultOperation.performOperation() + if ("$x" != "Success(1)") return "$x" + return "OK" +} 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 07a56d26c6c..413a71ba91e 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 @@ -21689,6 +21689,18 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { public void testLambdaTakesResultThroughBridge() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/result/lambdaTakesResultThroughBridge.kt"); } + + @Test + @TestMetadata("returnGenericMultiModule.kt") + public void testReturnGenericMultiModule() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/result/returnGenericMultiModule.kt"); + } + + @Test + @TestMetadata("returnGenericSingleModule.kt") + public void testReturnGenericSingleModule() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/result/returnGenericSingleModule.kt"); + } } @Nested 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 a7041d3efc0..09d3adf31b2 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 @@ -22109,6 +22109,18 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes public void testLambdaTakesResultThroughBridge() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/result/lambdaTakesResultThroughBridge.kt"); } + + @Test + @TestMetadata("returnGenericMultiModule.kt") + public void testReturnGenericMultiModule() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/result/returnGenericMultiModule.kt"); + } + + @Test + @TestMetadata("returnGenericSingleModule.kt") + public void testReturnGenericSingleModule() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/result/returnGenericSingleModule.kt"); + } } @Nested diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index ae006cba636..f144af74900 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -18196,6 +18196,16 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes public void testLambdaTakesResultThroughBridge() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/result/lambdaTakesResultThroughBridge.kt"); } + + @TestMetadata("returnGenericMultiModule.kt") + public void testReturnGenericMultiModule() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/result/returnGenericMultiModule.kt"); + } + + @TestMetadata("returnGenericSingleModule.kt") + public void testReturnGenericSingleModule() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/result/returnGenericSingleModule.kt"); + } } @TestMetadata("compiler/testData/codegen/box/inlineClasses/returnResult") diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java index f405d20e02c..e0fd380b5e4 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java @@ -17203,6 +17203,18 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { public void testLambdaTakesResultThroughBridge() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/result/lambdaTakesResultThroughBridge.kt"); } + + @Test + @TestMetadata("returnGenericMultiModule.kt") + public void testReturnGenericMultiModule() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/result/returnGenericMultiModule.kt"); + } + + @Test + @TestMetadata("returnGenericSingleModule.kt") + public void testReturnGenericSingleModule() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/result/returnGenericSingleModule.kt"); + } } @Nested diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java index 71d93b7d7bd..3b256e8eec5 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java @@ -17167,6 +17167,18 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { public void testLambdaTakesResultThroughBridge() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/result/lambdaTakesResultThroughBridge.kt"); } + + @Test + @TestMetadata("returnGenericMultiModule.kt") + public void testReturnGenericMultiModule() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/result/returnGenericMultiModule.kt"); + } + + @Test + @TestMetadata("returnGenericSingleModule.kt") + public void testReturnGenericSingleModule() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/result/returnGenericSingleModule.kt"); + } } @Nested diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testOld/wasm/semantics/IrCodegenBoxWasmTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testOld/wasm/semantics/IrCodegenBoxWasmTestGenerated.java index 2c534ab6c11..8f679164e5a 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testOld/wasm/semantics/IrCodegenBoxWasmTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testOld/wasm/semantics/IrCodegenBoxWasmTestGenerated.java @@ -14586,6 +14586,16 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest public void testLambdaTakesResultThroughBridge() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/result/lambdaTakesResultThroughBridge.kt"); } + + @TestMetadata("returnGenericMultiModule.kt") + public void testReturnGenericMultiModule() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/result/returnGenericMultiModule.kt"); + } + + @TestMetadata("returnGenericSingleModule.kt") + public void testReturnGenericSingleModule() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/result/returnGenericSingleModule.kt"); + } } @TestMetadata("compiler/testData/codegen/box/inlineClasses/returnResult") diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/ExternalTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/ExternalTestGenerated.java index 9ebe44defd3..556d870fac5 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/ExternalTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/ExternalTestGenerated.java @@ -18971,6 +18971,18 @@ public class ExternalTestGenerated extends AbstractExternalNativeBlackBoxTest { public void testLambdaTakesResultThroughBridge() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/result/lambdaTakesResultThroughBridge.kt"); } + + @Test + @TestMetadata("returnGenericMultiModule.kt") + public void testReturnGenericMultiModule() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/result/returnGenericMultiModule.kt"); + } + + @Test + @TestMetadata("returnGenericSingleModule.kt") + public void testReturnGenericSingleModule() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/result/returnGenericSingleModule.kt"); + } } @Nested