Intrinsics for 'reversed': generate in-const-bound ranges as countable

#KT-21323 In Progress
This commit is contained in:
Dmitry Petrov
2017-12-11 12:20:21 +03:00
parent 1775f294f4
commit 821843e13f
9 changed files with 147 additions and 5 deletions
@@ -0,0 +1,25 @@
// WITH_RUNTIME
import kotlin.test.*
fun intLow() = 4
fun intHigh() = 1
fun longLow() = 4L
fun longHigh() = 1L
fun charLow() = '4'
fun charHigh() = '1'
fun box(): String {
for (i in (intLow() .. intHigh()).reversed()) {
throw AssertionError("Loop should not be executed")
}
for (i in (longLow() .. longHigh()).reversed()) {
throw AssertionError("Loop should not be executed")
}
for (i in (charLow() .. charHigh()).reversed()) {
throw AssertionError("Loop should not be executed")
}
return "OK"
}
@@ -0,0 +1,31 @@
// WITH_RUNTIME
import kotlin.test.*
fun intLow() = 1
fun intHigh() = 4
fun longLow() = 1L
fun longHigh() = 4L
fun charLow() = '1'
fun charHigh() = '4'
fun box(): String {
var sum = 0
for (i in (intLow() .. intHigh()).reversed()) {
sum = sum * 10 + i
}
assertEquals(4321, sum)
var sumL = 0L
for (i in (longLow() .. longHigh()).reversed()) {
sumL = sumL * 10 + i
}
assertEquals(4321L, sumL)
var sumC = 0
for (i in (charLow() .. charHigh()).reversed()) {
sumC = sumC * 10 + i.toInt() - '0'.toInt()
}
assertEquals(4321, sumC)
return "OK"
}
@@ -14,6 +14,8 @@ fun box(): String {
}
// 0 reversed
// 0 getStart
// 0 getEnd
// 0 getFirst
// 0 getLast
// 0 getStep
@@ -24,6 +24,10 @@ fun box(): String {
}
// 0 reversed
// 0 getStart
// 0 getEnd
// 0 getFirst
// 0 getLast
// 0 getStep
// 0 getStep
// 2 IF_ICMPEQ
// ^ 1 for char progression, 1 for long progression