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:
Dmitry Petrov
2017-07-07 12:31:23 +03:00
parent fc3e9318d9
commit 905a16e1df
14 changed files with 298 additions and 44 deletions
@@ -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"
}