From da93ff1a3080410a3edddc51926e143a18b45b06 Mon Sep 17 00:00:00 2001 From: Mikhael Bogdanov Date: Thu, 6 Sep 2018 14:15:14 +0200 Subject: [PATCH] Properly cast right-hand side value for inline property setter #KT-22649 Fixed --- .../jetbrains/kotlin/codegen/StackValue.java | 5 ++++- .../codegen/boxInline/property/kt22649.kt | 17 +++++++++++++++++ .../BlackBoxInlineCodegenTestGenerated.java | 5 +++++ ...eKotlinAgainstInlineKotlinTestGenerated.java | 5 +++++ .../IrBlackBoxInlineCodegenTestGenerated.java | 5 +++++ ...IrPropertyAccessorsInlineTestsGenerated.java | 5 +++++ .../PropertyAccessorsInlineTestsGenerated.java | 5 +++++ 7 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/codegen/boxInline/property/kt22649.kt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/StackValue.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/StackValue.java index 2a2e72ecbf8..ff768c55b92 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/StackValue.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/StackValue.java @@ -1619,7 +1619,10 @@ public abstract class StackValue { putReceiver(v, false); } callGenerator.processAndPutHiddenParameters(true); - callGenerator.putValueIfNeeded(new JvmKotlinType(rightSide.type, rightSide.kotlinType), rightSide); + callGenerator.putValueIfNeeded(new JvmKotlinType( + CollectionsKt.last(setter.getValueParameters()).getAsmType(), + CollectionsKt.last(setterDescriptor.getValueParameters()).getType()), + rightSide); callGenerator.putHiddenParamsIntoLocals(); callGenerator.genCall(setter, resolvedCall, false, codegen); } diff --git a/compiler/testData/codegen/boxInline/property/kt22649.kt b/compiler/testData/codegen/boxInline/property/kt22649.kt new file mode 100644 index 00000000000..0f2f73b6dee --- /dev/null +++ b/compiler/testData/codegen/boxInline/property/kt22649.kt @@ -0,0 +1,17 @@ +// FILE: 1.kt +var result = "" + +inline var apx:Int + get() = 0 + set(value) { result = if (value == 1) "OK" else "fail" } + + +// FILE: 2.kt +fun test(s: Int?) { + apx = s!! +} + +fun box() : String { + test(1) + return result +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java index f5e93c63b5b..4aa926a7504 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java @@ -2410,6 +2410,11 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo runTest("compiler/testData/codegen/boxInline/property/augAssignmentAndIncViaConvention.kt"); } + @TestMetadata("kt22649.kt") + public void testKt22649() throws Exception { + runTest("compiler/testData/codegen/boxInline/property/kt22649.kt"); + } + @TestMetadata("property.kt") public void testProperty() throws Exception { runTest("compiler/testData/codegen/boxInline/property/property.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java index a5a2c30a7b4..f57d50462c2 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java @@ -2410,6 +2410,11 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi runTest("compiler/testData/codegen/boxInline/property/augAssignmentAndIncViaConvention.kt"); } + @TestMetadata("kt22649.kt") + public void testKt22649() throws Exception { + runTest("compiler/testData/codegen/boxInline/property/kt22649.kt"); + } + @TestMetadata("property.kt") public void testProperty() throws Exception { runTest("compiler/testData/codegen/boxInline/property/property.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java index 5318cf36a61..60f5a774eef 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java @@ -2410,6 +2410,11 @@ public class IrBlackBoxInlineCodegenTestGenerated extends AbstractIrBlackBoxInli runTest("compiler/testData/codegen/boxInline/property/augAssignmentAndIncViaConvention.kt"); } + @TestMetadata("kt22649.kt") + public void testKt22649() throws Exception { + runTest("compiler/testData/codegen/boxInline/property/kt22649.kt"); + } + @TestMetadata("property.kt") public void testProperty() throws Exception { runTest("compiler/testData/codegen/boxInline/property/property.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrPropertyAccessorsInlineTestsGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrPropertyAccessorsInlineTestsGenerated.java index c5d224a9c4b..8ad4ff659c2 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrPropertyAccessorsInlineTestsGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrPropertyAccessorsInlineTestsGenerated.java @@ -59,6 +59,11 @@ public class IrPropertyAccessorsInlineTestsGenerated extends AbstractIrPropertyA runTest("compiler/testData/codegen/boxInline/property/augAssignmentAndIncViaConvention.kt"); } + @TestMetadata("kt22649.kt") + public void testKt22649() throws Exception { + runTest("compiler/testData/codegen/boxInline/property/kt22649.kt"); + } + @TestMetadata("property.kt") public void testProperty() throws Exception { runTest("compiler/testData/codegen/boxInline/property/property.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/PropertyAccessorsInlineTestsGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/PropertyAccessorsInlineTestsGenerated.java index 17b49f9f783..ca2dac45512 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/PropertyAccessorsInlineTestsGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/PropertyAccessorsInlineTestsGenerated.java @@ -59,6 +59,11 @@ public class PropertyAccessorsInlineTestsGenerated extends AbstractPropertyAcces runTest("compiler/testData/codegen/boxInline/property/augAssignmentAndIncViaConvention.kt"); } + @TestMetadata("kt22649.kt") + public void testKt22649() throws Exception { + runTest("compiler/testData/codegen/boxInline/property/kt22649.kt"); + } + @TestMetadata("property.kt") public void testProperty() throws Exception { runTest("compiler/testData/codegen/boxInline/property/property.kt");