Exhaustive when on sealed trees implemented #KT-13130 Fixed

Also #KT-13227 Fixed
This commit is contained in:
Mikhail Glukhikh
2017-01-18 18:40:42 +03:00
parent 3d7bcbdff9
commit 9625c32527
8 changed files with 292 additions and 36 deletions
@@ -0,0 +1,34 @@
sealed class Base {
sealed class A : Base() {
object A1 : A()
sealed class A2 : A()
}
sealed class B : Base() {
sealed class B1 : B()
object B2 : B()
}
fun foo() = when (this) {
is A -> 1
is B.B1 -> 2
B.B2 -> 3
// No else required
}
fun bar() = <!NO_ELSE_IN_WHEN!>when<!> (this) {
is A -> 1
is B.B1 -> 2
}
fun baz() = when (this) {
is A -> 1
B.B2 -> 3
// No else required (no possible B1 instances)
}
fun negated() = when (this) {
!is A -> 1
A.A1 -> 2
is A.A2 -> 3
}
}