Support const-bound counter loop generation for 'downTo'
This commit is contained in:
+16
@@ -0,0 +1,16 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun low() = 4
|
||||
fun high() = 1
|
||||
|
||||
fun box(): String {
|
||||
var sum = 0
|
||||
for (i in low() downTo high()) {
|
||||
sum = sum * 10 + i
|
||||
}
|
||||
assertEquals(4321, sum)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
const val M = 0.toChar()
|
||||
|
||||
fun box(): String {
|
||||
var count = 0
|
||||
for (i in M downTo M) {
|
||||
++count
|
||||
if (count > 1) {
|
||||
throw AssertionError("Loop should be executed once")
|
||||
}
|
||||
}
|
||||
if (count != 1) throw AssertionError("Should be executed once")
|
||||
return "OK"
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
const val M = Int.MIN_VALUE
|
||||
|
||||
fun box(): String {
|
||||
var count = 0
|
||||
for (i in M downTo M) {
|
||||
++count
|
||||
if (count > 1) {
|
||||
throw AssertionError("Loop should be executed once")
|
||||
}
|
||||
}
|
||||
if (count != 1) throw AssertionError("Should be executed once")
|
||||
return "OK"
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
const val M = Long.MIN_VALUE
|
||||
|
||||
fun box(): String {
|
||||
var count = 0
|
||||
for (i in M downTo M) {
|
||||
++count
|
||||
if (count > 1) {
|
||||
throw AssertionError("Loop should be executed once")
|
||||
}
|
||||
}
|
||||
if (count != 1) throw AssertionError("Should be executed once")
|
||||
return "OK"
|
||||
}
|
||||
+4
-1
@@ -29,4 +29,7 @@ fun box(): String {
|
||||
// 0 getFirst
|
||||
// 0 getLast
|
||||
// 0 getStep
|
||||
// 0 IF_ICMPEQ
|
||||
// 0 IFEQ
|
||||
// 0 IF_ICMPEQ
|
||||
// 2 IF_ICMPLT
|
||||
// 1 LCMP
|
||||
@@ -12,4 +12,6 @@ fun test(): Int {
|
||||
// 0 getStart
|
||||
// 0 getEnd
|
||||
// 0 getFirst
|
||||
// 0 getLast
|
||||
// 0 getLast
|
||||
// 0 IF_ICMPEQ
|
||||
// 1 IF_ICMPLT
|
||||
Reference in New Issue
Block a user