Hey :wave: Anyone having issues using `when` expr...
# announcements
a
Hey 👋 Anyone having issues using
when
expressions? I keep getting a warning telling me it should be exhaustive but I have every possible branch filled in? I am only seeing this after updating the Kotlin plugin in Android Studio to 1.4.30
s
Code/Screenshot?
s
maybe you forgot to add
null
in cases?
a
Hey - so I’m seeing the error in production code so can’t copy and paste right now but I’ll try to reproduce the scenario and send in later. The argument in the
when
statement isn’t nullable :( I will be back with more details later 🙌🏻✌🏻
s
I see, why don’t you take a screenshot? 🙂
r
I do!
the problem is when your sealed class is in other module than your
when
statement
Module A has this
And Module B (depending on A) throws this
the code compiles tho
s
ah I see.
right now I do not see why, but you could simply replace Exhaustive.No -> False with else -> False
?
r
it removes the error, but then I loose the beauty of an exhaustive statement when I add new types to the sealed class
s
ah right.
pardon me!
a
@Rafal thank you so much - I couldn’t figure out what was happening 😅 Is this a bug or an improvement in the Kotlin plugin?
i
Looks like a bug to me - “False positive” to be exact
👍 3
m
My guess would be that one branch is based on instance of and the other is based on equality. If you replace the No check with an is, it will probably show exhaustive.
r
Thanks for reporting the issue! I didn’t know where to report it 🙈
🙌 1