diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/StackValue.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/StackValue.java index a1660ce8f8d..4293155c538 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/StackValue.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/StackValue.java @@ -1478,18 +1478,21 @@ public abstract class StackValue { } Type typeOfValueOnStack = getter.getReturnType(); + KotlinType kotlinTypeOfValueOnStack = getterDescriptor.getReturnType(); if (DescriptorUtils.isAnnotationClass(descriptor.getContainingDeclaration())) { if (this.type.equals(K_CLASS_TYPE)) { wrapJavaClassIntoKClass(v); typeOfValueOnStack = K_CLASS_TYPE; + kotlinTypeOfValueOnStack = null; } else if (this.type.equals(K_CLASS_ARRAY_TYPE)) { wrapJavaClassesIntoKClasses(v); typeOfValueOnStack = K_CLASS_ARRAY_TYPE; + kotlinTypeOfValueOnStack = null; } } - coerce(typeOfValueOnStack, type, v); + coerce(typeOfValueOnStack, kotlinTypeOfValueOnStack, type, kotlinType, v); KotlinType returnType = descriptor.getReturnType(); if (returnType != null && KotlinBuiltIns.isNothing(returnType)) { @@ -1563,10 +1566,14 @@ public abstract class StackValue { v.visitFieldInsn(isStaticStore ? PUTSTATIC : PUTFIELD, backingFieldOwner.getInternalName(), fieldName, this.type.getDescriptor()); } else { - coerce(topOfStackType, ArraysKt.last(setter.getParameterTypes()), v); + PropertySetterDescriptor setterDescriptor = descriptor.getSetter(); + KotlinType setterLastParameterType = + setterDescriptor != null ? CollectionsKt.last(setterDescriptor.getValueParameters()).getReturnType() : null; + + coerce(topOfStackType, topOfStackKotlinType, ArraysKt.last(this.setter.getParameterTypes()), setterLastParameterType, v); setter.genInvokeInstruction(v); - Type returnType = setter.getReturnType(); + Type returnType = this.setter.getReturnType(); if (returnType != Type.VOID_TYPE) { pop(v, returnType); } diff --git a/compiler/testData/codegen/box/inlineClasses/kt25771.kt b/compiler/testData/codegen/box/inlineClasses/kt25771.kt new file mode 100644 index 00000000000..83bd568a02e --- /dev/null +++ b/compiler/testData/codegen/box/inlineClasses/kt25771.kt @@ -0,0 +1,36 @@ +// !LANGUAGE: +InlineClasses +// IGNORE_BACKEND: JVM_IR, JS_IR + +inline class SuccessOrFailure(val value: Any?) { + val isFailure: Boolean get() = value is Failure + + public companion object { + public inline fun success(value: T): SuccessOrFailure = + SuccessOrFailure(value) + + public inline fun failure(exception: Throwable): SuccessOrFailure = + SuccessOrFailure(Failure(exception)) + } + + class Failure ( + val exception: Throwable + ) +} + +inline fun runCatching(block: () -> R): SuccessOrFailure { + return try { + SuccessOrFailure.success(block()) + } catch (e: Throwable) { + SuccessOrFailure.failure(e) + } +} + +class Box(val x: T) + +fun box(): String { + val r = runCatching { TODO() } + val b = Box(r) + if (r.isFailure != b.x.isFailure || !r.isFailure) return "Fail: r=${r.isFailure}; b.x=${b.x.isFailure}" + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/inlineClasses/unboxReceiverOnCallingMethodFromInlineClass.kt b/compiler/testData/codegen/box/inlineClasses/unboxReceiverOnCallingMethodFromInlineClass.kt new file mode 100644 index 00000000000..4b9a63aac4f --- /dev/null +++ b/compiler/testData/codegen/box/inlineClasses/unboxReceiverOnCallingMethodFromInlineClass.kt @@ -0,0 +1,18 @@ +// !LANGUAGE: +InlineClasses +// IGNORE_BACKEND: JVM_IR + +inline class Foo(val s: Any) { + fun isString(): Boolean = s is String +} + +class Box(val x: T) + +fun box(): String { + val f = Foo("string") + val g = Box(f) + val r = g.x.isString() + + if (!r) return "Fail" + + return "OK" +} \ 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 8dbcb235cf7..ebd0138c145 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -11353,6 +11353,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/inlineClasses/kt25246.kt"); } + @TestMetadata("kt25771.kt") + public void testKt25771() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/kt25771.kt"); + } + @TestMetadata("noAssertionsOnInlineClassBasedOnNullableType.kt") public void testNoAssertionsOnInlineClassBasedOnNullableType() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/noAssertionsOnInlineClassBasedOnNullableType.kt"); @@ -11398,6 +11403,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/inlineClasses/UIntArraySortExample.kt"); } + @TestMetadata("unboxReceiverOnCallingMethodFromInlineClass.kt") + public void testUnboxReceiverOnCallingMethodFromInlineClass() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/unboxReceiverOnCallingMethodFromInlineClass.kt"); + } + @TestMetadata("useInlineClassesInsideElvisOperator.kt") public void testUseInlineClassesInsideElvisOperator() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/useInlineClassesInsideElvisOperator.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 129374e61bf..5102602db92 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -11353,6 +11353,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/inlineClasses/kt25246.kt"); } + @TestMetadata("kt25771.kt") + public void testKt25771() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/kt25771.kt"); + } + @TestMetadata("noAssertionsOnInlineClassBasedOnNullableType.kt") public void testNoAssertionsOnInlineClassBasedOnNullableType() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/noAssertionsOnInlineClassBasedOnNullableType.kt"); @@ -11398,6 +11403,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/inlineClasses/UIntArraySortExample.kt"); } + @TestMetadata("unboxReceiverOnCallingMethodFromInlineClass.kt") + public void testUnboxReceiverOnCallingMethodFromInlineClass() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/unboxReceiverOnCallingMethodFromInlineClass.kt"); + } + @TestMetadata("useInlineClassesInsideElvisOperator.kt") public void testUseInlineClassesInsideElvisOperator() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/useInlineClassesInsideElvisOperator.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 8d6a62cb161..5fc97d9c5bc 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -11353,6 +11353,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/inlineClasses/kt25246.kt"); } + @TestMetadata("kt25771.kt") + public void testKt25771() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/kt25771.kt"); + } + @TestMetadata("noAssertionsOnInlineClassBasedOnNullableType.kt") public void testNoAssertionsOnInlineClassBasedOnNullableType() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/noAssertionsOnInlineClassBasedOnNullableType.kt"); @@ -11398,6 +11403,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/inlineClasses/UIntArraySortExample.kt"); } + @TestMetadata("unboxReceiverOnCallingMethodFromInlineClass.kt") + public void testUnboxReceiverOnCallingMethodFromInlineClass() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/unboxReceiverOnCallingMethodFromInlineClass.kt"); + } + @TestMetadata("useInlineClassesInsideElvisOperator.kt") public void testUseInlineClassesInsideElvisOperator() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/useInlineClassesInsideElvisOperator.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 6ad6a5c6581..0acff87e47d 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 @@ -9983,6 +9983,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTest("compiler/testData/codegen/box/inlineClasses/kt25246.kt"); } + @TestMetadata("kt25771.kt") + public void testKt25771() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/kt25771.kt"); + } + @TestMetadata("noAssertionsOnInlineClassBasedOnNullableType.kt") public void testNoAssertionsOnInlineClassBasedOnNullableType() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/noAssertionsOnInlineClassBasedOnNullableType.kt"); @@ -10028,6 +10033,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTest("compiler/testData/codegen/box/inlineClasses/UIntArraySortExample.kt"); } + @TestMetadata("unboxReceiverOnCallingMethodFromInlineClass.kt") + public void testUnboxReceiverOnCallingMethodFromInlineClass() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/unboxReceiverOnCallingMethodFromInlineClass.kt"); + } + @TestMetadata("useInlineClassesInsideElvisOperator.kt") public void testUseInlineClassesInsideElvisOperator() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/useInlineClassesInsideElvisOperator.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 b18bdbd21b8..7037b75c94d 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 @@ -10978,6 +10978,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/inlineClasses/kt25246.kt"); } + @TestMetadata("kt25771.kt") + public void testKt25771() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/kt25771.kt"); + } + @TestMetadata("noAssertionsOnInlineClassBasedOnNullableType.kt") public void testNoAssertionsOnInlineClassBasedOnNullableType() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/noAssertionsOnInlineClassBasedOnNullableType.kt"); @@ -11023,6 +11028,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/inlineClasses/UIntArraySortExample.kt"); } + @TestMetadata("unboxReceiverOnCallingMethodFromInlineClass.kt") + public void testUnboxReceiverOnCallingMethodFromInlineClass() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/unboxReceiverOnCallingMethodFromInlineClass.kt"); + } + @TestMetadata("useInlineClassesInsideElvisOperator.kt") public void testUseInlineClassesInsideElvisOperator() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/useInlineClassesInsideElvisOperator.kt");