0

When using sealed classes, the compiler only checks for subtypes in the same file.

One of the big selling points of sealed classes is the exhaustive checks when using a when expression. So why isn't this implemented?

In 1 file I have:

class C : B()

In another file I have:

sealed class A

open class B : A()

fun switch(input: A) =
    when(input) {
        is B -> Unit
//        is C -> Unit - I expect a compiler error since this is a subtype and it's commented out
    }
Ivan
  • 239
  • 1
  • 13

1 Answers1

0

As Eugene Petrenko commented, the is B case that is required by the compiler covers all subclasses of B.

Ivan
  • 239
  • 1
  • 13