Maintain proper evaluation order for 'a in x .. y'
As of Kotlin 1.0 and 1.1, expression 'a in x .. y' is considered equivalent to 'x.rangeTo(y).a', and should be evaluated in the following order: 1. x 2. y 3. a 4. compare x with a 5. compare y with a (if needed)
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
val order = StringBuilder()
|
||||
|
||||
inline fun expectOrder(at: String, expected: String, body: () -> Unit) {
|
||||
order.setLength(0)
|
||||
body()
|
||||
if (order.toString() != expected) throw AssertionError("$at: expected: $expected, actual: $order")
|
||||
}
|
||||
|
||||
fun low(i: Int): Int {
|
||||
order.append("L")
|
||||
return i
|
||||
}
|
||||
|
||||
fun high(i: Int): Int {
|
||||
order.append("H")
|
||||
return i
|
||||
}
|
||||
|
||||
fun x(i: Int): Int {
|
||||
order.append("X")
|
||||
return i
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
expectOrder("0 in 1 .. 3", "HLX") { x(0) in high(3) downTo low(1) }
|
||||
expectOrder("0 !in 1 .. 3", "HLX") { x(0) !in high(3) downTo low(1) }
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user