diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java index 8d1f405d148..0a52e80b315 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java @@ -491,12 +491,12 @@ public class ExpressionCodegen extends KtVisitor impleme Label end = new Label(); - gen(thenExpression, asmType); + gen(thenExpression, asmType, kotlinType); v.goTo(end); v.mark(elseLabel); - gen(elseExpression, asmType); + gen(elseExpression, asmType, kotlinType); markLineNumber(expression, isStatement); v.mark(end); diff --git a/compiler/testData/codegen/box/inlineClasses/correctBoxingForBranchExpressions.kt b/compiler/testData/codegen/box/inlineClasses/correctBoxingForBranchExpressions.kt new file mode 100644 index 00000000000..f805018d1b6 --- /dev/null +++ b/compiler/testData/codegen/box/inlineClasses/correctBoxingForBranchExpressions.kt @@ -0,0 +1,19 @@ +// !LANGUAGE: +InlineClasses + +interface Base { + fun result(): Int +} + +inline class Inlined(val x: Int) : Base { + override fun result(): Int = x +} + +fun foo(b: Boolean): Base { + return if (b) Inlined(0) else Inlined(1) +} + +fun box(): String { + if (foo(true).result() != 0) return "Fail 1" + if (foo(false).result() != 1) return "Fail 2" + return "OK" +} \ No newline at end of file diff --git a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 08172f9d17a..3910ee87677 100644 --- a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -11244,6 +11244,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/inlineClasses/computablePropertyInsideInlineClass.kt"); } + @TestMetadata("correctBoxingForBranchExpressions.kt") + public void testCorrectBoxingForBranchExpressions() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/correctBoxingForBranchExpressions.kt"); + } + @TestMetadata("createInlineClassInArgumentPosition.kt") public void testCreateInlineClassInArgumentPosition() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/createInlineClassInArgumentPosition.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index b5974e2aca6..ec47030fe62 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -11244,6 +11244,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/inlineClasses/computablePropertyInsideInlineClass.kt"); } + @TestMetadata("correctBoxingForBranchExpressions.kt") + public void testCorrectBoxingForBranchExpressions() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/correctBoxingForBranchExpressions.kt"); + } + @TestMetadata("createInlineClassInArgumentPosition.kt") public void testCreateInlineClassInArgumentPosition() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/createInlineClassInArgumentPosition.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 05c63c5ec66..85a05507344 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -11244,6 +11244,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/inlineClasses/computablePropertyInsideInlineClass.kt"); } + @TestMetadata("correctBoxingForBranchExpressions.kt") + public void testCorrectBoxingForBranchExpressions() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/correctBoxingForBranchExpressions.kt"); + } + @TestMetadata("createInlineClassInArgumentPosition.kt") public void testCreateInlineClassInArgumentPosition() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/createInlineClassInArgumentPosition.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrJsCodegenBoxTestGenerated.java index 598af11994a..b5fee2a570f 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrJsCodegenBoxTestGenerated.java @@ -10904,6 +10904,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTest("compiler/testData/codegen/box/inlineClasses/computablePropertyInsideInlineClass.kt"); } + @TestMetadata("correctBoxingForBranchExpressions.kt") + public void testCorrectBoxingForBranchExpressions() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/correctBoxingForBranchExpressions.kt"); + } + @TestMetadata("createInlineClassInArgumentPosition.kt") public void testCreateInlineClassInArgumentPosition() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/createInlineClassInArgumentPosition.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 e014bd04c67..c3c8edcc591 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 @@ -9782,6 +9782,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/inlineClasses/computablePropertyInsideInlineClass.kt"); } + @TestMetadata("correctBoxingForBranchExpressions.kt") + public void testCorrectBoxingForBranchExpressions() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/correctBoxingForBranchExpressions.kt"); + } + @TestMetadata("createInlineClassInArgumentPosition.kt") public void testCreateInlineClassInArgumentPosition() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/createInlineClassInArgumentPosition.kt");