Hi there, is there a ticket/KEPP about supporting ...
# language-proposals
h
Hi there, is there a ticket/KEPP about supporting local enums, that is enums which are defined in a function body? I think this would be pretty handy e.g. when writing api examples (like with dokka).
r
do you have an example?
h
Copy code
fun iteratorAPI() {
    
    enum class Gender{male, female}
    
    data class Person(val name: String, val gender: Gender, val heightCm: Int, val weightKg: Double)

    val persons = listOf(
        Person("Max", Gender.male, 192, 80.3),
        Person("Anna", Gender.female, 162, 56.3),
        Person("Maria", Gender.female, 172, 66.3)
    )
}
Which fails with
image.png
d
Yes, that would be handy, but either such enums can't capture anything from local scope (and then you can move enum class declaration to top-level and make it private-in-file, which is not exactly what you want, but solves the problem), or the corresponding enum entries are not singletons (and the class can't be mapped to a platform enum, e.g. on JVM).
h
Hmm, ok thanks for the details. With respect to my dokka usecase moving them to class level is not really an option. So I guess I need to use some rather odd construct like
Copy code
class Gender{ val male=Gender(); val female=Gender(); }
to mimic an enum when providing self-contained API docs via dokka.