diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/PropertyCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/PropertyCodegen.java index 09867966028..9cd43a4cda9 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/PropertyCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/PropertyCodegen.java @@ -620,7 +620,8 @@ public class PropertyCodegen { assert delegate != null : "No delegate for delegated property: " + propertyDescriptor; StackValue lastValue = invokeDelegatedPropertyConventionMethod(codegen, resolvedCall, delegate, propertyDescriptor); Type asmType = signature.getReturnType(); - lastValue.put(asmType, v); + KotlinType kotlinReturnType = propertyAccessorDescriptor.getOriginal().getReturnType(); + lastValue.put(asmType, kotlinReturnType, v); v.areturn(asmType); } } diff --git a/compiler/testData/codegen/box/inlineClasses/propertyDelegation/delegatedPropertyOfInlineClassType.kt b/compiler/testData/codegen/box/inlineClasses/propertyDelegation/delegatedPropertyOfInlineClassType.kt new file mode 100644 index 00000000000..7a4acc741f2 --- /dev/null +++ b/compiler/testData/codegen/box/inlineClasses/propertyDelegation/delegatedPropertyOfInlineClassType.kt @@ -0,0 +1,56 @@ +// IGNORE_BACKEND: JVM_IR + +import kotlin.reflect.KProperty + +inline class ICInt(val i: Int) +inline class ICLong(val l: Long) +inline class ICOverIC(val o: ICLong) + +class Delegate(var f: () -> T) { + operator fun getValue(thisRef: Any?, property: KProperty<*>): T = f() + operator fun setValue(thisRef: Any?, property: KProperty<*>, value: T) { + f = { value } + } +} + +object Demo { + val i0 by Delegate { ICInt(1) } + val l0 by Delegate { ICLong(2L) } + val o0 by Delegate { ICOverIC(ICLong(3L)) } + + val i1: ICInt by Delegate { ICInt(11) } + val l1: ICLong by Delegate { ICLong(22) } + val o1: ICOverIC by Delegate { ICOverIC(ICLong(33)) } + + var i2 by Delegate { ICInt(0) } + var l2 by Delegate { ICLong(0) } + var o2 by Delegate { ICOverIC(ICLong(0)) } +} + +fun box(): String { + if (Demo.i0.i != 1) return "Fail 1" + if (Demo.l0.l != 2L) return "Fail 2" + if (Demo.o0.o.l != 3L) return "Fail 3" + + if (Demo.i1.i != 11) return "Fail 2 1" + if (Demo.l1.l != 22L) return "Fail 2 2" + if (Demo.o1.o.l != 33L) return "Fail 2 3" + + Demo.i2 = ICInt(33) + Demo.l2 = ICLong(33) + Demo.o2 = ICOverIC(ICLong(33)) + + if (Demo.i2.i != 33) return "Fail 3 1" + if (Demo.l2.l != 33L) return "Fail 3 2" + if (Demo.o2.o.l != 33L) return "Fail 3 3" + + val localI by Delegate { ICInt(44) } + val localL by Delegate { ICLong(44) } + val localO by Delegate { ICOverIC(ICLong(44)) } + + if (localI.i != 44) return "Fail 4 1" + if (localL.l != 44L) return "Fail 4 2" + if (localO.o.l != 44L) return "Fail 4 3" + + 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 093f21148f5..d27b12d4f34 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -12745,6 +12745,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/inlineClasses/propertyDelegation/delegateTopLevelVarToInlineClass.kt"); } + @TestMetadata("delegatedPropertyOfInlineClassType.kt") + public void testDelegatedPropertyOfInlineClassType() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/propertyDelegation/delegatedPropertyOfInlineClassType.kt"); + } + @TestMetadata("kt27070.kt") public void testKt27070() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/propertyDelegation/kt27070.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 819998ffe72..0f80acf7041 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -12745,6 +12745,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/inlineClasses/propertyDelegation/delegateTopLevelVarToInlineClass.kt"); } + @TestMetadata("delegatedPropertyOfInlineClassType.kt") + public void testDelegatedPropertyOfInlineClassType() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/propertyDelegation/delegatedPropertyOfInlineClassType.kt"); + } + @TestMetadata("kt27070.kt") public void testKt27070() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/propertyDelegation/kt27070.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index ca1641cbce4..7899b09bdd5 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -12750,6 +12750,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/inlineClasses/propertyDelegation/delegateTopLevelVarToInlineClass.kt"); } + @TestMetadata("delegatedPropertyOfInlineClassType.kt") + public void testDelegatedPropertyOfInlineClassType() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/propertyDelegation/delegatedPropertyOfInlineClassType.kt"); + } + @TestMetadata("kt27070.kt") public void testKt27070() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/propertyDelegation/kt27070.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 0e90434655b..8bfd2815a9c 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 @@ -11135,6 +11135,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTest("compiler/testData/codegen/box/inlineClasses/propertyDelegation/delegateTopLevelVarToInlineClass.kt"); } + @TestMetadata("delegatedPropertyOfInlineClassType.kt") + public void testDelegatedPropertyOfInlineClassType() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/propertyDelegation/delegatedPropertyOfInlineClassType.kt"); + } + @TestMetadata("kt27070.kt") public void testKt27070() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/propertyDelegation/kt27070.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 d20b261f81a..72026922cc8 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 @@ -12180,6 +12180,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/inlineClasses/propertyDelegation/delegateTopLevelVarToInlineClass.kt"); } + @TestMetadata("delegatedPropertyOfInlineClassType.kt") + public void testDelegatedPropertyOfInlineClassType() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/propertyDelegation/delegatedPropertyOfInlineClassType.kt"); + } + @TestMetadata("kt27070.kt") public void testKt27070() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/propertyDelegation/kt27070.kt");