Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@optics generates bad code for sealed hierarchies with changing property nullability #3380

Closed
sindrenm opened this issue Feb 27, 2024 · 0 comments · Fixed by #3382
Closed

Comments

@sindrenm
Copy link

The Arrow Optics KSP plugin generates bad code for sealed hierarchies that contains nullable properties in the parent, but that becomes non-nullable in a child class.

This is a new issue with arrow-optics 1.2.2 that was not present in 1.1.5.

Library: io.arrow-kt:arrow-optics-ksp-plugin 1.2.2

Reproduction

The following will generate code that does not compile in arrow-optics 1.2.2:

import arrow.optics.optics

@optics
sealed interface Base {
    val prop: String?

    companion object
}

@optics
data class Child(override val prop: String) : Base {
    companion object
}

The generated bad code:

inline val Base.Companion.nullableProp: Lens<Base, String?>
    inline get() = Lens(
        get = { base: Base -> base.`prop` },
        set = { base: Base, value: String? ->
            when (base) {
                is Child -> base.copy(`prop` = value) // value: String? cannot be passed to prop: String
            }
        },
    )
serras added a commit that referenced this issue Feb 28, 2024
Ignore properties in sealed hierarchies where the type changes across children
nomisRev pushed a commit that referenced this issue Feb 28, 2024
@serras serras mentioned this issue Feb 28, 2024
22 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant