https://kotlinlang.org logo
#getting-started
Title
# getting-started
m

MR3Y

03/10/2024, 12:08 PM
Where can I find the corresponding youtrack issue that should make
when
in the following code snippet smart enough to infer it is already exhaustive? my searching skills are failing me here.
Copy code
fun main() {
	printFoo(Foo.C)
}

fun printFoo(parameter: Foo) {
    if (parameter is Foo.C || parameter is Foo.Bar) {
        // Compiler error: 'when' expression must be exhaustive, add necessary 'A', 'B' branches or 'else' branch instead
        val message = when(parameter) {
            is Foo.C -> "C"
            is Foo.Bar.D -> "D"
            is Foo.Bar.E, is Foo.Bar.F -> "" 
        }
        println(message)
    }
}

sealed interface Foo {
    data object A : Foo

    data object B : Foo

    data object C : Foo

    sealed interface Bar : Foo {
        data object D : Bar

        data object E : Bar

        data object F : Bar
    }
}