diff --git a/compiler/testData/codegen/uptoDownto.kt b/compiler/testData/codegen/uptoDownto.kt new file mode 100644 index 00000000000..fed0339d1e9 --- /dev/null +++ b/compiler/testData/codegen/uptoDownto.kt @@ -0,0 +1,38 @@ +fun box(): String { + val sb = StringBuilder() + + fun ap(i : Int) { + if (sb.size != 0) sb.append(" ") + sb.append(i) + } + + for (i in 0..0) { + ap(i) + } + sb.append(";") + + for (i in 0..1) { + ap(i) + } + sb.append(";") + + for (i in IntRange(0, 1)) { + ap(i) + } + sb.append(";") + + for (i in 0 downto 0) { + ap(i) + } + sb.append(";") + + for (i in 1 downto 0) { + ap(i) + } + + return if (sb.toString() == "0; 0 1; 0; 0; 1 0") "OK" else sb.toString()!! +} + +fun main(args: Array) { + println(box()) +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/codegen/StdlibTest.java b/compiler/tests/org/jetbrains/jet/codegen/StdlibTest.java index 8199f93daa6..fa3bd584046 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/StdlibTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/StdlibTest.java @@ -330,4 +330,7 @@ public class StdlibTest extends CodegenTestCase { blackBoxFile("regressions/kt1800.kt"); } + public void testUptoDownto() { + blackBoxFile("uptoDownto.kt"); + } } diff --git a/runtime/src/jet/runtime/Ranges.java b/runtime/src/jet/runtime/Ranges.java index 96eab78f2bb..3a4823ac94e 100644 --- a/runtime/src/jet/runtime/Ranges.java +++ b/runtime/src/jet/runtime/Ranges.java @@ -38,7 +38,7 @@ public class Ranges { } public static ByteRange downTo(byte from, byte to) { - if (from > to) { + if (from >= to) { return new ByteRange(from, to - from - 1); } else { @@ -56,7 +56,7 @@ public class Ranges { } public static ShortRange downTo(byte from, short to) { - if (from > to) { + if (from >= to) { return new ShortRange(from, to - from - 1); } else { @@ -74,7 +74,7 @@ public class Ranges { } public static IntRange downTo(byte from, int to) { - if (from > to) { + if (from >= to) { return new IntRange(from, to - from - 1); } else { @@ -92,7 +92,7 @@ public class Ranges { } public static LongRange downTo(byte from, long to) { - if (from > to) { + if (from >= to) { return new LongRange(from, to - from - 1); } else { @@ -126,7 +126,7 @@ public class Ranges { } public static CharRange downTo(byte from, char to) { - if (from > to) { + if (from >= to) { return new CharRange((char) from, to - from - 1); } else { @@ -144,7 +144,7 @@ public class Ranges { } public static ShortRange downTo(short from, byte to) { - if (from > to) { + if (from >= to) { return new ShortRange(from, to - from - 1); } else { @@ -162,7 +162,7 @@ public class Ranges { } public static ShortRange downTo(short from, short to) { - if (from > to) { + if (from >= to) { return new ShortRange(from, to - from - 1); } else { @@ -180,7 +180,7 @@ public class Ranges { } public static IntRange downTo(short from, int to) { - if (from > to) { + if (from >= to) { return new IntRange(from, to - from - 1); } else { @@ -198,7 +198,7 @@ public class Ranges { } public static LongRange downTo(short from, long to) { - if (from > to) { + if (from >= to) { return new LongRange(from, to - from - 1); } else { @@ -232,7 +232,7 @@ public class Ranges { } public static ShortRange downTo(short from, char to) { - if (from > to) { + if (from >= to) { return new ShortRange(from, to - from - 1); } else { @@ -250,7 +250,7 @@ public class Ranges { } public static IntRange downTo(int from, byte to) { - if (from > to) { + if (from >= to) { return new IntRange(from, to - from - 1); } else { @@ -268,7 +268,7 @@ public class Ranges { } public static IntRange downTo(int from, short to) { - if (from > to) { + if (from >= to) { return new IntRange(from, to - from - 1); } else { @@ -286,7 +286,7 @@ public class Ranges { } public static IntRange downTo(int from, int to) { - if (from > to) { + if (from >= to) { return new IntRange(from, to - from - 1); } else { @@ -304,7 +304,7 @@ public class Ranges { } public static LongRange downTo(int from, long to) { - if (from > to) { + if (from >= to) { return new LongRange(from, to - from - 1); } else { @@ -338,7 +338,7 @@ public class Ranges { } public static IntRange downTo(int from, char to) { - if (from > to) { + if (from >= to) { return new IntRange(from, to - from - 1); } else { @@ -356,7 +356,7 @@ public class Ranges { } public static LongRange downTo(long from, byte to) { - if (from > to) { + if (from >= to) { return new LongRange(from, to - from - 1); } else { @@ -374,7 +374,7 @@ public class Ranges { } public static LongRange downTo(long from, short to) { - if (from > to) { + if (from >= to) { return new LongRange(from, to - from - 1); } else { @@ -392,7 +392,7 @@ public class Ranges { } public static LongRange downTo(long from, int to) { - if (from > to) { + if (from >= to) { return new LongRange(from, to - from - 1); } else { @@ -410,7 +410,7 @@ public class Ranges { } public static LongRange downTo(long from, long to) { - if (from > to) { + if (from >= to) { return new LongRange(from, to - from - 1); } else { @@ -444,7 +444,7 @@ public class Ranges { } public static LongRange downTo(long from, char to) { - if (from > to) { + if (from >= to) { return new LongRange(from, to - from - 1); } else { @@ -574,7 +574,7 @@ public class Ranges { } public static CharRange downTo(char from, byte to) { - if (from > to) { + if (from >= to) { return new CharRange(from, to - from - 1); } else { @@ -592,7 +592,7 @@ public class Ranges { } public static ShortRange downTo(char from, short to) { - if (from > to) { + if (from >= to) { return new ShortRange((short) from, to - from - 1); } else { @@ -610,7 +610,7 @@ public class Ranges { } public static IntRange downTo(char from, int to) { - if (from > to) { + if (from >= to) { return new IntRange(from, to - from - 1); } else { @@ -628,7 +628,7 @@ public class Ranges { } public static LongRange downTo(char from, long to) { - if (from > to) { + if (from >= to) { return new LongRange(from, to - from - 1); } else { @@ -662,7 +662,7 @@ public class Ranges { } public static CharRange downTo(char from, char to) { - if (from > to) { + if (from >= to) { return new CharRange(from, to - from - 1); } else { @@ -715,7 +715,7 @@ public class Ranges { " }\n" + "}"); System.out.println("\npublic static " + resType + " downTo(" + t1 + " from, " + t2 + " to) {" + - "\n if(from > to) {\n" + + "\n if(from >= to) {\n" + " return new " + resType + "(from, to-from-1);\n" + " }\n" + " else {\n" +