jwstegemann / fritz2

Easily build reactive web-apps in Kotlin based on flows and coroutines.
https://www.fritz2.dev
MIT License
653 stars 28 forks source link

@Lenses Annotation fails creating Delegating- and Upcasting-Lenses for empty sealed Base Type #893

Closed Lysander closed 3 weeks ago

Lysander commented 3 weeks ago

The introduced feature of PR #874 fails for empty sealed types like the following:

@Lenses
sealed interface Field {
    // no common property defined here
    companion object
}

@Lenses
data class Birthday(
    val date: LocalDate
) : Field {
    companion object
}

@Lenses
data class Phone(
    val number: String
) : Field {
    companion object
}

This should definitely create those lenses even if this hierarchy shares no common property!

Also the check is ignored, that every child class must be annotated with Lenses. This should fail compiling:

@Lenses
sealed interface Field {
    companion object
}

@Lenses
data class Birthday(
    val date: LocalDate
) : Field {
    companion object
}

// no annotation -> processor should fail with error!
data class Phone(
    val number: String
) : Field {
    companion object
}

Should also work if the common properties are marked with @NoLens of course!

@Lenses
sealed interface Field {
    @NoLens
    val ignored: Int

    // no common property defined here
    companion object
}