Did you know it's possible to create non-exhaustiv...
# feed
c
Did you know it's possible to create non-exhaustive enums? Well, it is!
K 6
👀 3
y
Fwiw, there's the sealed enum ksp plugin that can generate entries and such for you. Using a sealed hierarchy as an enum means, then, that you can add some
internal class NonExhaustive(val nothing: Nothing): MyEnum
, so within your library, you can still get exhaustivity, but outside, users will be forced to use
else
. Even better, this prevents you from accidentally assuming exhaustivity in public inline methods because
NonExhaustive
is not
@PublishedApi
Another devious trick: you can
RequiresOptIn
with a non-public type... Users thus can't opt-in, unless they do it using the compiler argument
c
Another devious trick: you can
RequiresOptIn
with a non-public type... Users thus can't opt-in, unless they do it using the compiler argument
The result is the same as with
DeprecationLevel.Error
y
Of course, but (I believe) they can't suppress it then, although you lose
ReplaceWith
. It also means that you don't need to use error suppression