Fix exhaustiveness check for when with subject variable

This commit is contained in:
Dmitry Petrov
2018-06-09 14:04:31 +03:00
parent 6949610dcb
commit b4dc3dc91b
6 changed files with 69 additions and 37 deletions
@@ -0,0 +1,20 @@
// !LANGUAGE: +VariableDeclarationInWhenSubject
// !DIAGNOSTICS: -UNUSED_VARIABLE
sealed class Either
class Left : Either()
class Right : Either()
fun testSmartcastToSealedInSubjectInitializer1(x: Any?) {
val y1 = when (val either = x as Either) {
is Left -> "L"
is Right -> "R"
}
}
fun testSmartcastToSealedInSubjectInitializer2(x: Any?) {
val y2 = <!NO_ELSE_IN_WHEN!>when<!> (val either: Any = x as Either) { // NB explicit type annotation
is Left -> "L"
is Right -> "R"
}
}