diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java index b8cea418627..93feec6e5e4 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java @@ -356,11 +356,16 @@ public class ExpressionCodegen extends KtVisitor impleme return (ScriptContext) context; } - public StackValue genLazy(KtElement expr, Type type) { + private StackValue genLazy(KtElement expr, Type type) { StackValue value = gen(expr); return StackValue.coercion(value, type, null); } + private StackValue genLazy(KtElement expr, Type type, KotlinType kotlinType) { + StackValue value = gen(expr); + return StackValue.coercion(value, type, kotlinType); + } + private StackValue genStatement(KtElement statement) { return genQualified(StackValue.none(), statement, statementVisitor); } @@ -3008,7 +3013,7 @@ public class ExpressionCodegen extends KtVisitor impleme return StackValue.coercion(generateSafeQualifiedExpression((KtSafeQualifiedExpression) expression, ifnull), type, kotlinType); } else { - return genLazy(expression, type); + return genLazy(expression, type, kotlinType); } } diff --git a/compiler/testData/codegen/box/inlineClasses/elvisWithInlineClassAndNullConstant.kt b/compiler/testData/codegen/box/inlineClasses/elvisWithInlineClassAndNullConstant.kt new file mode 100644 index 00000000000..676a7f7042f --- /dev/null +++ b/compiler/testData/codegen/box/inlineClasses/elvisWithInlineClassAndNullConstant.kt @@ -0,0 +1,16 @@ +// !LANGUAGE: +InlineClasses + +inline class UInt(private val data: Int) { + fun result(): String = if (data == 1) "OK" else "fail" +} + +fun f(): UInt { + val unull = UInt(1) ?: null + return nonNull(unull) +} + +fun nonNull(u: UInt?) = u!! + +fun box(): String { + return f().result() +} \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeText/inlineClasses/boxInlineClassInsideElvisWithNullConstant.kt b/compiler/testData/codegen/bytecodeText/inlineClasses/boxInlineClassInsideElvisWithNullConstant.kt new file mode 100644 index 00000000000..35f6bfef64c --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/inlineClasses/boxInlineClassInsideElvisWithNullConstant.kt @@ -0,0 +1,13 @@ +// !LANGUAGE: +InlineClasses + +inline class UInt(private val data: Int) + +fun f() { + val unull = UInt(1) ?: null +} + +// 1 INVOKESTATIC UInt\$Erased.box +// 0 INVOKEVIRTUAL UInt.unbox + +// 0 valueOf +// 0 intValue \ 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 ab4d647320a..7985406709f 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 @@ -11073,6 +11073,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/inlineClasses/createInlineClassInArgumentPosition.kt"); } + @TestMetadata("elvisWithInlineClassAndNullConstant.kt") + public void testElvisWithInlineClassAndNullConstant() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/elvisWithInlineClassAndNullConstant.kt"); + } + @TestMetadata("emptyConstructorForInlineClass.kt") public void testEmptyConstructorForInlineClass() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/emptyConstructorForInlineClass.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index d7d3e165c4d..5327b2bf96e 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -11073,6 +11073,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/inlineClasses/createInlineClassInArgumentPosition.kt"); } + @TestMetadata("elvisWithInlineClassAndNullConstant.kt") + public void testElvisWithInlineClassAndNullConstant() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/elvisWithInlineClassAndNullConstant.kt"); + } + @TestMetadata("emptyConstructorForInlineClass.kt") public void testEmptyConstructorForInlineClass() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/emptyConstructorForInlineClass.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java index 120350a172e..17256130a96 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java @@ -1983,6 +1983,11 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest { runTest("compiler/testData/codegen/bytecodeText/inlineClasses/assertionsForParametersOfInlineClassTypes.kt"); } + @TestMetadata("boxInlineClassInsideElvisWithNullConstant.kt") + public void testBoxInlineClassInsideElvisWithNullConstant() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/inlineClasses/boxInlineClassInsideElvisWithNullConstant.kt"); + } + @TestMetadata("boxInlineClassesOnPassingToVarargs.kt") public void testBoxInlineClassesOnPassingToVarargs() throws Exception { runTest("compiler/testData/codegen/bytecodeText/inlineClasses/boxInlineClassesOnPassingToVarargs.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 7448571d630..2dce0b407b0 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -11073,6 +11073,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/inlineClasses/createInlineClassInArgumentPosition.kt"); } + @TestMetadata("elvisWithInlineClassAndNullConstant.kt") + public void testElvisWithInlineClassAndNullConstant() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/elvisWithInlineClassAndNullConstant.kt"); + } + @TestMetadata("emptyConstructorForInlineClass.kt") public void testEmptyConstructorForInlineClass() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/emptyConstructorForInlineClass.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 d8c15fc74fe..f7475aee1f3 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 @@ -9630,6 +9630,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/inlineClasses/createInlineClassInArgumentPosition.kt"); } + @TestMetadata("elvisWithInlineClassAndNullConstant.kt") + public void testElvisWithInlineClassAndNullConstant() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/elvisWithInlineClassAndNullConstant.kt"); + } + @TestMetadata("emptyConstructorForInlineClass.kt") public void testEmptyConstructorForInlineClass() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/emptyConstructorForInlineClass.kt");