Support Long and Char in const-bounded counter loop generation
If the loop end value is a compile-time constant (best we can do now), and it is safe to iterate over a given range using "naive" for loop (using '<=' or '>=' in loop condition), generate such loops for Longs and Chars as well Ints (Bytes, Shorts).
This commit is contained in:
+13
@@ -0,0 +1,13 @@
|
||||
const val M = 0xFFFF.toChar()
|
||||
|
||||
fun box(): String {
|
||||
var count = 0
|
||||
for (i in M .. M) {
|
||||
++count
|
||||
if (count > 1) {
|
||||
throw AssertionError("Loop should be executed once")
|
||||
}
|
||||
}
|
||||
if (count != 1) throw AssertionError("Should be executed once")
|
||||
return "OK"
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
const val M = Int.MAX_VALUE
|
||||
|
||||
fun box(): String {
|
||||
var step = 0
|
||||
for (i in M .. M) {
|
||||
++step
|
||||
if (step > 1) throw AssertionError("Should be executed once")
|
||||
}
|
||||
if (step != 1) throw AssertionError("Should be executed once")
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
const val M = Long.MAX_VALUE
|
||||
|
||||
fun box(): String {
|
||||
var count = 0
|
||||
for (i in M .. M) {
|
||||
++count
|
||||
if (count > 1) {
|
||||
throw AssertionError("Loop should be executed once")
|
||||
}
|
||||
}
|
||||
if (count != 1) throw AssertionError("Should be executed once")
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user