I've got a `sealed class` I'm checking for with a ...
# compiler
r
I've got a
sealed class
I'm checking for with a
when
and a lot of branches checking for the specific subtypes via
is Type.SubType
- how can I force a completeness check?
v
Is it not?
d
When expressions and statements with enum/sealed type/boolean in subject are required to be exhaustive by default since Kotlin 1.6 https://kotlinlang.org/docs/whatsnew16.html#stable-exhaustive-when-statements-for-enum-sealed-and-boolean-subjects
v
r
That's weird, it compiles just fine
Copy code
when (cardMessage) {
            is CardMessage.Accept -> onNewDesiredState(DesiredState.AcceptCall)
            is CardMessage.Reject -> onNewDesiredState(DesiredState.RejectCall)
        }
And the class:
Copy code
@Parcelize sealed class CardMessage : Parcelable {
    @Parcelize sealed class RssSeries(val url: Uri): CardMessage()
    @Parcelize object Accept: Command() {
        override fun toString(): String {
            return "Accept()"
        }
    }
    @Parcelize object Reject: Command() {
        override fun toString(): String {
            return "Reject()"
        }
    }
}
c
what checks are missing?
v
Command
maybe?
c
Command is sealed so its abstract
v
Ah, right, then I also don't see what could be missing 🙂
r
Ah, bad example then, I shortened it a bit too much.
Replaced
Command
with
RssSeries
c
ok but its still abstract
r
Oh, that explains it 🤦
'when' expression must be exhaustive, add necessary 'Maybe' branch or 'else' branch instead