Exhaustive whens without else and 'Nothing' as the result are considered 'implicit exhaustive'
This commit is contained in:
committed by
Mikhail Glukhikh
parent
d62d7dd84f
commit
b93894953d
@@ -2,11 +2,11 @@ enum class Color { RED, GREEN, BLUE }
|
||||
|
||||
fun foo(arr: Array<Color>): Color {
|
||||
loop@ for (color in arr) {
|
||||
when (color) {
|
||||
<!DEBUG_INFO_IMPLICIT_EXHAUSTIVE!>when (color) {
|
||||
Color.RED -> return color
|
||||
Color.GREEN -> break@loop
|
||||
Color.BLUE -> if (arr.size == 1) return color else continue@loop
|
||||
}
|
||||
}<!>
|
||||
// Unreachable
|
||||
<!UNREACHABLE_CODE!>return Color.BLUE<!>
|
||||
}
|
||||
|
||||
+2
-2
@@ -13,8 +13,8 @@ public enum J {
|
||||
// FILE: K.kt
|
||||
|
||||
fun foo(): Int {
|
||||
when (<!WHEN_ENUM_CAN_BE_NULL_IN_JAVA!>J.create()<!>) {
|
||||
<!DEBUG_INFO_IMPLICIT_EXHAUSTIVE!>when (<!WHEN_ENUM_CAN_BE_NULL_IN_JAVA!>J.create()<!>) {
|
||||
J.A -> return 1
|
||||
J.B -> return 2
|
||||
}
|
||||
}<!>
|
||||
}
|
||||
|
||||
@@ -3,11 +3,11 @@ enum class Direction {
|
||||
}
|
||||
|
||||
fun foo(dir: Direction): Int {
|
||||
when (dir) {
|
||||
<!DEBUG_INFO_IMPLICIT_EXHAUSTIVE!>when (dir) {
|
||||
Direction.NORTH -> return 1
|
||||
Direction.SOUTH -> return 2
|
||||
Direction.WEST -> return 3
|
||||
Direction.EAST -> return 4
|
||||
}
|
||||
}<!>
|
||||
// See KT-1882: no return is needed at the end
|
||||
}
|
||||
@@ -3,12 +3,12 @@ enum class Direction {
|
||||
}
|
||||
|
||||
fun foo(dir: Direction): Int {
|
||||
when (dir) {
|
||||
<!DEBUG_INFO_IMPLICIT_EXHAUSTIVE!>when (dir) {
|
||||
Direction.NORTH -> return 1
|
||||
Direction.SOUTH -> throw AssertionError("!!!")
|
||||
Direction.WEST -> return 3
|
||||
Direction.EAST -> return 4
|
||||
}
|
||||
}<!>
|
||||
// Error: Unreachable code. Return is not required.
|
||||
<!UNREACHABLE_CODE!>if (dir == Direction.SOUTH) return 2<!>
|
||||
}
|
||||
Reference in New Issue
Block a user