Ranges on the LHS of when-expressions can cause a CompilationException:
fun main(args: Array<String>) {
val a = Math.abs(-1)
val c = a..10 // works
val b = 5
when (b) {
in c -> foo() // works
in a..10 -> foo() // compilation exception
in Math.abs(-1)..10 -> foo() // compilation exception
}
}
fun foo() {}
Feels like a compiler bug or am I doing something wrong? Couldn’t find an issue for this in YouTrack.
UPDATE: a) I’m using kotlin-1.1.51. b) Adding parentheses doesn’t seem to help either.
Regards,
Peter