-
-
Notifications
You must be signed in to change notification settings - Fork 114
Closed
Labels
enhancementNew feature or requestNew feature or requestkotlinPull requests that update Kotlin codePull requests that update Kotlin code
Milestone
Description
Is your feature request related to a problem? Please describe.
Add sealed keyword` to generated interfaces and unions in order to enable exhaustive type-checking in written code. For example
sealed interface Animal {}
data class Cat(val foo: String): Animal
data class Dog(val bar: String): Animal
fun cases(obj: Animal) {
return when (obj) {
is Cat -> "foo"
is Dog -> "bar"; // Removing this line will fail compilation
}
}
The Kotlin language will default to exhaustive when statements (expressions are already exhaustive) in version 1.7, which will make it easier to take advantage of this feature. https://kotlinlang.org/docs/whatsnew1530.html#exhaustive-when-statements-for-sealed-and-boolean-subjects
Describe the solution you'd like
A generateSealedInterfaces build parameter that if true will add the sealed keyword to generated interfaces in Kotlin
Describe alternatives you've considered
n/a
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestkotlinPull requests that update Kotlin codePull requests that update Kotlin code