Marc Knaup
02/26/2020, 5:03 AM@Suppress
? E.g. @Enforce
.
For example with non-exhaustive when
expressions:
‘when’ expression on sealed classes is recommended to be exhaustive, add ‘is …’ branch or ‘else’ branch insteadWith
@Suppress("NON_EXHAUSTIVE_WHEN_ON_SEALED_CLASS")
the warning is gone.
With @Enforce("NON_EXHAUSTIVE_WHEN_ON_SEALED_CLASS")
the warning will turn into an error.
That would allow catching missing branches earlier (e.g. when adding a new subclass to a sealed class).
It would even allow developers to turn any warning into an error for specific code, i.e. depending on the use case.
I guess that would be most useful for compiler warnings as the non-exhaustive when
warning is an inspection and wouldn’t cause the compilation process to actually fail 🤔spand
02/26/2020, 6:11 AMMarc Knaup
02/26/2020, 6:50 AMsimon.vergauwen
02/26/2020, 8:53 AMNON_EXHAUSTIVE_WHEN_ON_SEALED_CLASS
a compile error, and Suppress
places where you want to ignore it?simon.vergauwen
02/26/2020, 8:54 AMMarc Knaup
02/26/2020, 9:14 AMsimon.vergauwen
02/26/2020, 9:16 AMspand
02/26/2020, 9:16 AMelse ->
instead of an annotationMarc Knaup
02/26/2020, 9:22 AMelse -> {}
and else -> Unit
are weird tbh. And changing default behavior would break existing code.
I do agree that non-exhaustive `when`s are a minority :)Marc Knaup
02/26/2020, 9:24 AMopen when
? 😄
(assuming new default)gian
02/26/2020, 10:40 AMwhen
exhaustiveness on a local level, you can do something like
inline fun <T> T.exhaustive() = Unit
and then call when { }.exhaustive()
Marc Knaup
02/26/2020, 11:08 AM