From 21cdf9dd5bf97cb1772cac98fbe240cbc8e45ab1 Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Tue, 5 Sep 2017 11:42:03 +0300 Subject: [PATCH] Add cast to expected type in call-based in-expression generation #KT-20106 Fixed --- .../range/inExpression/CallBasedInExpressionGenerator.kt | 1 + compiler/testData/codegen/box/ranges/contains/kt20106.kt | 7 +++++++ .../kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java | 6 ++++++ .../kotlin/codegen/BlackBoxCodegenTestGenerated.java | 6 ++++++ .../kotlin/codegen/LightAnalysisModeTestGenerated.java | 6 ++++++ .../js/test/semantics/JsCodegenBoxTestGenerated.java | 6 ++++++ 6 files changed, 32 insertions(+) create mode 100644 compiler/testData/codegen/box/ranges/contains/kt20106.kt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/range/inExpression/CallBasedInExpressionGenerator.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/range/inExpression/CallBasedInExpressionGenerator.kt index 7228825be19..1cf2b60e864 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/range/inExpression/CallBasedInExpressionGenerator.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/range/inExpression/CallBasedInExpressionGenerator.kt @@ -39,6 +39,7 @@ class CallBasedInExpressionGenerator( object : BranchedValue(argument, null, argument.type, Opcodes.IFEQ) { override fun putSelector(type: Type, v: InstructionAdapter) { invokeFunction(v) + coerceTo(type, v) } override fun condJump(jumpLabel: Label, v: InstructionAdapter, jumpIfFalse: Boolean) { diff --git a/compiler/testData/codegen/box/ranges/contains/kt20106.kt b/compiler/testData/codegen/box/ranges/contains/kt20106.kt new file mode 100644 index 00000000000..2b2097f1e04 --- /dev/null +++ b/compiler/testData/codegen/box/ranges/contains/kt20106.kt @@ -0,0 +1,7 @@ +// WITH_RUNTIME + +fun box(): String { + val strSet = setOf("a", "b") + val xx = "a" to ("a" in strSet) + return if (!xx.second) "fail" else "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 53e920e1c3f..4a14bf69b0b 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 @@ -13777,6 +13777,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes doTest(fileName); } + @TestMetadata("kt20106.kt") + public void testKt20106() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ranges/contains/kt20106.kt"); + doTest(fileName); + } + @TestMetadata("nullableInPrimitiveRange.kt") public void testNullableInPrimitiveRange() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ranges/contains/nullableInPrimitiveRange.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 848013635c7..8732565fd80 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -13777,6 +13777,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } + @TestMetadata("kt20106.kt") + public void testKt20106() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ranges/contains/kt20106.kt"); + doTest(fileName); + } + @TestMetadata("nullableInPrimitiveRange.kt") public void testNullableInPrimitiveRange() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ranges/contains/nullableInPrimitiveRange.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 26b535de4a1..6b8005810cb 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -13777,6 +13777,12 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes doTest(fileName); } + @TestMetadata("kt20106.kt") + public void testKt20106() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ranges/contains/kt20106.kt"); + doTest(fileName); + } + @TestMetadata("nullableInPrimitiveRange.kt") public void testNullableInPrimitiveRange() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ranges/contains/nullableInPrimitiveRange.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 e9057d7a0e0..09235632fde 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 @@ -15463,6 +15463,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { doTest(fileName); } + @TestMetadata("kt20106.kt") + public void testKt20106() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ranges/contains/kt20106.kt"); + doTest(fileName); + } + @TestMetadata("nullableInPrimitiveRange.kt") public void testNullableInPrimitiveRange() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ranges/contains/nullableInPrimitiveRange.kt");