From 7175361c97e3a69a3fe45964696958e4c1ea6018 Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Fri, 30 Jun 2017 15:58:34 +0300 Subject: [PATCH] Ensure that BranchedValue for in/!in work well with boolean operations --- .../contains/inRangeLiteralComposition.kt | 27 +++++++++++++++++++ .../ir/IrBlackBoxCodegenTestGenerated.java | 6 +++++ .../codegen/BlackBoxCodegenTestGenerated.java | 6 +++++ .../LightAnalysisModeTestGenerated.java | 6 +++++ .../semantics/JsCodegenBoxTestGenerated.java | 6 +++++ 5 files changed, 51 insertions(+) create mode 100644 compiler/testData/codegen/box/ranges/contains/inRangeLiteralComposition.kt diff --git a/compiler/testData/codegen/box/ranges/contains/inRangeLiteralComposition.kt b/compiler/testData/codegen/box/ranges/contains/inRangeLiteralComposition.kt new file mode 100644 index 00000000000..2e086ceafcd --- /dev/null +++ b/compiler/testData/codegen/box/ranges/contains/inRangeLiteralComposition.kt @@ -0,0 +1,27 @@ +// WITH_RUNTIME + +val i1 = 1 +val i2 = 2 +val i3 = 3 + +fun box(): String { + if (!(i2 in i1 .. i3 && i1 !in i2 .. i3)) return "Fail 1 &&" + if (!(i2 in i1 .. i3 || i1 !in i2 .. i3)) return "Fail 1 ||" + + // const-folded in JVM BE + if (!(2 in 1 .. 3 && 1 !in 2 .. 3)) return "Fail 2 &&" + if (!(2 in 1 .. 3 || 1 !in 2 .. 3)) return "Fail 2 ||" + + val xs = listOf(1, 2, 3) + if (!(1 in xs && 10 !in xs)) return "Fail 3 &&" + if (!(1 in xs || 10 !in xs)) return "Fail 3 ||" + + val iarr = intArrayOf(1, 2, 3) + if (!(1 in iarr && 10 !in iarr)) return "Fail 4 &&" + if (!(1 in iarr || 10 !in iarr)) return "Fail 4 ||" + + if (!("b" in "a" .. "c" && "a" !in "b" .. "c")) return "Fail 5 &&" + if (!("b" in "a" .. "c" || "a" !in "b" .. "c")) return "Fail 5 ||" + + return "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 a733cae6ced..23bd62a4861 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 @@ -13255,6 +13255,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes doTest(fileName); } + @TestMetadata("inRangeLiteralComposition.kt") + public void testInRangeLiteralComposition() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ranges/contains/inRangeLiteralComposition.kt"); + doTest(fileName); + } + @TestMetadata("inRangeOfComparable.kt") public void testInRangeOfComparable() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ranges/contains/inRangeOfComparable.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index d93f5c3a714..660b51d8675 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -13255,6 +13255,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } + @TestMetadata("inRangeLiteralComposition.kt") + public void testInRangeLiteralComposition() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ranges/contains/inRangeLiteralComposition.kt"); + doTest(fileName); + } + @TestMetadata("inRangeOfComparable.kt") public void testInRangeOfComparable() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ranges/contains/inRangeOfComparable.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index b4eab3af414..6dc7600d6f1 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -13255,6 +13255,12 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes doTest(fileName); } + @TestMetadata("inRangeLiteralComposition.kt") + public void testInRangeLiteralComposition() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ranges/contains/inRangeLiteralComposition.kt"); + doTest(fileName); + } + @TestMetadata("inRangeOfComparable.kt") public void testInRangeOfComparable() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ranges/contains/inRangeOfComparable.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 9e71e7213d2..b806f283119 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 @@ -14911,6 +14911,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { doTest(fileName); } + @TestMetadata("inRangeLiteralComposition.kt") + public void testInRangeLiteralComposition() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ranges/contains/inRangeLiteralComposition.kt"); + doTest(fileName); + } + @TestMetadata("inRangeOfComparable.kt") public void testInRangeOfComparable() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ranges/contains/inRangeOfComparable.kt");