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:
+27
@@ -0,0 +1,27 @@
|
||||
// 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 list(): List<Int> {
|
||||
order.append("L")
|
||||
return emptyList()
|
||||
}
|
||||
|
||||
|
||||
fun x(i: Int): Int {
|
||||
order.append("X")
|
||||
return i
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
expectOrder("1 in []", "LX") { x(1) in list() }
|
||||
expectOrder("1 !in []", "LX") { x(1) !in list() }
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user