Implicit exhaustive whens now have exception in else branch #KT-8700 Fixed

This commit is contained in:
Mikhail Glukhikh
2015-12-04 18:43:44 +03:00
committed by Mikhail Glukhikh
parent 011a9f23b9
commit 7d6ccc40c2
16 changed files with 167 additions and 18 deletions
@@ -0,0 +1,10 @@
enum class A { V }
fun box(): String {
val a: A = A.V
val b: Boolean
when (a) {
A.V -> b = true
}
return if (b) "OK" else "FAIL"
}
@@ -0,0 +1,8 @@
enum class A { V }
fun box(): String {
val a: A = A.V
when (a) {
A.V -> return "OK"
}
}
@@ -0,0 +1,15 @@
sealed class A {
object B : A()
class C : A()
}
fun box(): String {
val a: A = A.C()
val b: Boolean
when (a) {
A.B -> b = true
is A.C -> b = false
}
return if (!b) "OK" else "FAIL"
}
@@ -0,0 +1,14 @@
enum class Color { RED, GREEN, BLUE }
fun foo(arr: Array<Color>): Color {
loop@ for (color in arr) {
when (color) {
Color.RED -> return color
Color.GREEN -> break@loop
Color.BLUE -> if (arr.size == 1) return color else continue@loop
}
}
return Color.GREEN
}
fun box() = if (foo(arrayOf(Color.BLUE, Color.GREEN)) == Color.GREEN) "OK" else "FAIL"
@@ -0,0 +1,14 @@
enum class A { V }
fun box(): String {
val a: A = A.V
val b: Boolean
when (a) {
A.V -> b = true
}
return if (b) "OK" else "FAIL"
}
// 0 TABLESWITCH
// 1 LOOKUPSWITCH
// 1 ATHROW
@@ -0,0 +1,12 @@
enum class A { V }
fun box(): String {
val a: A = A.V
when (a) {
A.V -> return "OK"
}
}
// 0 TABLESWITCH
// 1 LOOKUPSWITCH
// 1 ATHROW
@@ -0,0 +1,19 @@
sealed class A {
object B : A()
class C : A()
}
fun box(): String {
val a: A = A.C()
val b: Boolean
when (a) {
A.B -> b = true
is A.C -> b = false
}
return if (!b) "OK" else "FAIL"
}
// 0 TABLESWITCH
// 0 LOOKUPSWITCH
// 1 ATHROW