Sealed class inheritance and constructors

I also ran into these problems several times while working with sealed classes. The ergonomy of sealed classes in general is not yet there where it should be but I’m sure that it can be improved over time.

I think that the following syntax could work in general:

sealed class Person(val id: Long, val name: String) {
    class Developer constructor super : Person(...)
    class Painter constructor super : Person(...)
}

The constructor super informs the compiler that we want to inherit the constructor in its full glory (hence, including possible default values) and the ... tells the compiler that we want it to insert the right stuff here. I’m not sure if the ... poses a problem to the lexer, maybe something else is required here.

PS: Where can one make language design proposals and contribute to Kotlin?

3 Likes