Issue with sealed classes and when

https://pl.kotl.in/yq8pbWPns

I’m wondering why it is work.
I didn’t provide when branch for ‘Unknown’ class and expect compile error but there no error at all. Compiled and running.

What is missing? Looks like I don’t understand how it should work but documentation said:

The key benefit of using sealed classes comes into play when you use them in a when expression. If it’s possible to verify that the statement covers all cases, you don’t need to add an else clause to the statement.

There is no when expression in your code.

Expression:

val a = when(...) { ... }

Statement:

when(...) { ... }
1 Like

Ok, thanks - got it.

This is too easy to miss … dangerous one.