Is there a way to force when statements to be exha...
# announcements
s
Is there a way to force when statements to be exhaustive officially yet? I remember it was talked about. Right now I’m just putting a
.let {}
at the end of my when statements.
a
c
I use the above. An official way is coming soon. Check the KEEP for it.
d
When with algebraic type (`Boolean`/sealed class/sealed interface/enum) in subject will be required to be exhaustive in Kotlin 1.7 In 1.6 such non exhaustive whens will be reported as warnings You can enable it in 1.5.30 (when it will be released) with compiler flag
-XXLanguage:+WarnAboutNonExhaustiveWhenOnAlgebraicTypes
(to report warnings) Also you can add
-XXLanguage:+ProhibitNonExhaustiveWhenOnAlgebraicTypes
to report errors
Also you can enable progressive mode (
-progressive
) to enable them https://kotlinlang.org/docs/compiler-reference.html#progressive
s
kind of “hack” would be just doing
return when(…)
even from Unit functions