# Issue with sealed classes and when

**URL:** <https://discuss.kotlinlang.org/t/issue-with-sealed-classes-and-when/14330>\
**Category:** Support\
**Created:** [September 19, 2019, 3:38pm UTC](https://discuss.kotlinlang.org/t/issue-with-sealed-classes-and-when/14330 "2019-09-19T15:38:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rstor](https://avatars.discourse-cdn.com/v4/letter/r/8baadc/32.png) [@rstor](https://discuss.kotlinlang.org/u/rstor)\
**Post date:** [September 19, 2019, 3:38pm UTC](https://discuss.kotlinlang.org/t/issue-with-sealed-classes-and-when/14330/1 "2019-09-19T15:38:13Z")

</div>

[https://pl.kotl.in/yq8pbWPns](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](https://kotlinlang.org/docs/reference/control-flow.html#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.

---

<div class="post-metadata">

**Author:** ![rrlynx](https://avatars.discourse-cdn.com/v4/letter/r/9de0a6/32.png) [@rrlynx](https://discuss.kotlinlang.org/u/rrlynx)\
**Post date:** [September 19, 2019, 3:43pm UTC](https://discuss.kotlinlang.org/t/issue-with-sealed-classes-and-when/14330/2 "2019-09-19T15:43:42Z")

</div>

There is no `when` _expression_ in your code.

Expression:

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

```

Statement:

```auto
when(...) { ... }

```

---

<div class="post-metadata">

**Author:** ![rstor](https://avatars.discourse-cdn.com/v4/letter/r/8baadc/32.png) [@rstor](https://discuss.kotlinlang.org/u/rstor)\
**Post date:** [September 19, 2019, 4:13pm UTC](https://discuss.kotlinlang.org/t/issue-with-sealed-classes-and-when/14330/3 "2019-09-19T16:13:57Z")

</div>

Ok, thanks - got it.

This is too easy to miss … dangerous one.
