Refactored tests for switch optimization of When expression
This commit is contained in:
committed by
Evgeny Gerashchenko
parent
95345a9bd4
commit
3bc1c45fde
@@ -0,0 +1,34 @@
|
||||
fun exhaustive(x: Int): Int {
|
||||
var r: Int
|
||||
when (x) {
|
||||
1 -> r = 1
|
||||
2 -> r = 2
|
||||
3 -> r = 3
|
||||
else -> r = 4
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
fun nonExhaustive(x: Int): Int {
|
||||
var r: Int = 4
|
||||
when (x) {
|
||||
1 -> r = 1
|
||||
2 -> r = 2
|
||||
3 -> r = 3
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var result = (0..3).map(::exhaustive).makeString()
|
||||
|
||||
if (result != "4, 1, 2, 3") return "exhaustive:" + result
|
||||
|
||||
result = (0..3).map(::nonExhaustive).makeString()
|
||||
|
||||
if (result != "4, 1, 2, 3") return "non-exhaustive:" + result
|
||||
return "OK"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user