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

Arnab

12/21/2021, 11:53 AM
Why is the compiler asking me for an
else
branch when I have covered all of the possible subclasses of
Foo
(sealed class) ? Was it always like this? I remember not having to implement an
else
branch before.
r

Rahul Rawat

12/21/2021, 11:55 AM
No it wasn’t recently I faced the same with enums as well
a

Arnab

12/21/2021, 12:30 PM
k

Klitos Kyriacou

12/21/2021, 12:33 PM
Your code sample compiles and runs just fine.
a

Arnab

12/21/2021, 1:09 PM
You can see in my screenshot that it doesn’t.
k

Klitos Kyriacou

12/21/2021, 2:00 PM
What version of Kotlin are you using? The code works in both 1.5.31, 1.6.0 and 1.6.10. Also, you can see it working here: https://pl.kotl.in/ELzXUsA6I
2 Views