From 120eba8d3d99c3fc42496d7cf08295ddcfcc8f73 Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Mon, 5 Apr 2021 15:47:35 +0300 Subject: [PATCH] Minor: add tests for KT-45893 --- .../FirBlackBoxCodegenTestGenerated.java | 12 ++++++++ .../forInDoubleRangeWithCustomIterator.kt | 29 +++++++++++++++++++ .../forInFloatRangeWithCustomIterator.kt | 29 +++++++++++++++++++ .../codegen/BlackBoxCodegenTestGenerated.java | 12 ++++++++ .../IrBlackBoxCodegenTestGenerated.java | 12 ++++++++ .../LightAnalysisModeTestGenerated.java | 10 +++++++ .../IrJsCodegenBoxES6TestGenerated.java | 10 +++++++ .../IrJsCodegenBoxTestGenerated.java | 10 +++++++ .../semantics/JsCodegenBoxTestGenerated.java | 10 +++++++ .../IrCodegenBoxWasmTestGenerated.java | 10 +++++++ 10 files changed, 144 insertions(+) create mode 100644 compiler/testData/codegen/box/ranges/forInDoubleRangeWithCustomIterator.kt create mode 100644 compiler/testData/codegen/box/ranges/forInFloatRangeWithCustomIterator.kt diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java index f4686863462..7b8959f8e50 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java @@ -28390,6 +28390,18 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/ranges/forInCustomIterable.kt"); } + @Test + @TestMetadata("forInDoubleRangeWithCustomIterator.kt") + public void testForInDoubleRangeWithCustomIterator() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInDoubleRangeWithCustomIterator.kt"); + } + + @Test + @TestMetadata("forInFloatRangeWithCustomIterator.kt") + public void testForInFloatRangeWithCustomIterator() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInFloatRangeWithCustomIterator.kt"); + } + @Test @TestMetadata("forInRangeLiteralWithMixedTypeBounds.kt") public void testForInRangeLiteralWithMixedTypeBounds() throws Exception { diff --git a/compiler/testData/codegen/box/ranges/forInDoubleRangeWithCustomIterator.kt b/compiler/testData/codegen/box/ranges/forInDoubleRangeWithCustomIterator.kt new file mode 100644 index 00000000000..08f0303ac13 --- /dev/null +++ b/compiler/testData/codegen/box/ranges/forInDoubleRangeWithCustomIterator.kt @@ -0,0 +1,29 @@ +// IGNORE_BACKEND: JVM +// WITH_RUNTIME +// KJS_WITH_FULL_RUNTIME + +operator fun ClosedRange.iterator() = + object : Iterator { + private var current = this@iterator.start + private val end = this@iterator.endInclusive + + override fun hasNext(): Boolean = + current <= end + + override fun next(): Double { + val next = current + current += 0.1 + return next + } + } + +fun box(): String { + var s = 0.0 + for (x in 0.0 .. 1.0) { + s += x + } + if (s != 5.5) + return "Failed: $s" + + return "OK" +} diff --git a/compiler/testData/codegen/box/ranges/forInFloatRangeWithCustomIterator.kt b/compiler/testData/codegen/box/ranges/forInFloatRangeWithCustomIterator.kt new file mode 100644 index 00000000000..b26be25fc4f --- /dev/null +++ b/compiler/testData/codegen/box/ranges/forInFloatRangeWithCustomIterator.kt @@ -0,0 +1,29 @@ +// IGNORE_BACKEND: JVM +// WITH_RUNTIME +// KJS_WITH_FULL_RUNTIME + +operator fun ClosedRange.iterator() = + object : Iterator { + private var current = this@iterator.start + private val end = this@iterator.endInclusive + + override fun hasNext(): Boolean = + current <= end + + override fun next(): Float { + val next = current + current += 0.125f + return next + } + } + +fun box(): String { + var s = 0.0 + for (x in 0.0f .. 1.0f) { + s += x + } + if (s != 4.5) + return "Failed: $s" + + return "OK" +} diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java index e8e52b25d58..6db0c4f597d 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java @@ -28372,6 +28372,18 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/ranges/forInCustomIterable.kt"); } + @Test + @TestMetadata("forInDoubleRangeWithCustomIterator.kt") + public void testForInDoubleRangeWithCustomIterator() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInDoubleRangeWithCustomIterator.kt"); + } + + @Test + @TestMetadata("forInFloatRangeWithCustomIterator.kt") + public void testForInFloatRangeWithCustomIterator() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInFloatRangeWithCustomIterator.kt"); + } + @Test @TestMetadata("forInRangeLiteralWithMixedTypeBounds.kt") public void testForInRangeLiteralWithMixedTypeBounds() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java index 28a50a9b8ed..2ec7e9bc64c 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java @@ -28390,6 +28390,18 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/ranges/forInCustomIterable.kt"); } + @Test + @TestMetadata("forInDoubleRangeWithCustomIterator.kt") + public void testForInDoubleRangeWithCustomIterator() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInDoubleRangeWithCustomIterator.kt"); + } + + @Test + @TestMetadata("forInFloatRangeWithCustomIterator.kt") + public void testForInFloatRangeWithCustomIterator() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInFloatRangeWithCustomIterator.kt"); + } + @Test @TestMetadata("forInRangeLiteralWithMixedTypeBounds.kt") public void testForInRangeLiteralWithMixedTypeBounds() throws Exception { diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 7e68bf1a52d..c3bee5eedd9 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -24124,6 +24124,16 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/ranges/forInCustomIterable.kt"); } + @TestMetadata("forInDoubleRangeWithCustomIterator.kt") + public void testForInDoubleRangeWithCustomIterator() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInDoubleRangeWithCustomIterator.kt"); + } + + @TestMetadata("forInFloatRangeWithCustomIterator.kt") + public void testForInFloatRangeWithCustomIterator() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInFloatRangeWithCustomIterator.kt"); + } + @TestMetadata("forInRangeLiteralWithMixedTypeBounds.kt") public void testForInRangeLiteralWithMixedTypeBounds() throws Exception { runTest("compiler/testData/codegen/box/ranges/forInRangeLiteralWithMixedTypeBounds.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java index 3521d466931..4e76d2a64c8 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java @@ -19213,6 +19213,16 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes runTest("compiler/testData/codegen/box/ranges/forInCustomIterable.kt"); } + @TestMetadata("forInDoubleRangeWithCustomIterator.kt") + public void testForInDoubleRangeWithCustomIterator() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInDoubleRangeWithCustomIterator.kt"); + } + + @TestMetadata("forInFloatRangeWithCustomIterator.kt") + public void testForInFloatRangeWithCustomIterator() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInFloatRangeWithCustomIterator.kt"); + } + @TestMetadata("forInRangeLiteralWithMixedTypeBounds.kt") public void testForInRangeLiteralWithMixedTypeBounds() throws Exception { runTest("compiler/testData/codegen/box/ranges/forInRangeLiteralWithMixedTypeBounds.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java index d043b0078a2..6c25c6e735e 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java @@ -18634,6 +18634,16 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTest("compiler/testData/codegen/box/ranges/forInCustomIterable.kt"); } + @TestMetadata("forInDoubleRangeWithCustomIterator.kt") + public void testForInDoubleRangeWithCustomIterator() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInDoubleRangeWithCustomIterator.kt"); + } + + @TestMetadata("forInFloatRangeWithCustomIterator.kt") + public void testForInFloatRangeWithCustomIterator() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInFloatRangeWithCustomIterator.kt"); + } + @TestMetadata("forInRangeLiteralWithMixedTypeBounds.kt") public void testForInRangeLiteralWithMixedTypeBounds() throws Exception { runTest("compiler/testData/codegen/box/ranges/forInRangeLiteralWithMixedTypeBounds.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index 2116954a047..bd19e2a3497 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -18684,6 +18684,16 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/ranges/forInCustomIterable.kt"); } + @TestMetadata("forInDoubleRangeWithCustomIterator.kt") + public void testForInDoubleRangeWithCustomIterator() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInDoubleRangeWithCustomIterator.kt"); + } + + @TestMetadata("forInFloatRangeWithCustomIterator.kt") + public void testForInFloatRangeWithCustomIterator() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInFloatRangeWithCustomIterator.kt"); + } + @TestMetadata("forInRangeLiteralWithMixedTypeBounds.kt") public void testForInRangeLiteralWithMixedTypeBounds() throws Exception { runTest("compiler/testData/codegen/box/ranges/forInRangeLiteralWithMixedTypeBounds.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java index ec57afc6388..2fd707cdb8a 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java @@ -11971,6 +11971,16 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest runTest("compiler/testData/codegen/box/ranges/forByteProgressionWithIntIncrement.kt"); } + @TestMetadata("forInDoubleRangeWithCustomIterator.kt") + public void testForInDoubleRangeWithCustomIterator() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInDoubleRangeWithCustomIterator.kt"); + } + + @TestMetadata("forInFloatRangeWithCustomIterator.kt") + public void testForInFloatRangeWithCustomIterator() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInFloatRangeWithCustomIterator.kt"); + } + @TestMetadata("forInRangeLiteralWithMixedTypeBounds.kt") public void testForInRangeLiteralWithMixedTypeBounds() throws Exception { runTest("compiler/testData/codegen/box/ranges/forInRangeLiteralWithMixedTypeBounds.kt");