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

Value classes break State class no zero argument constructor usage #704

Open
brentwatson opened this issue Dec 6, 2023 · 1 comment
Open

Comments

@brentwatson
Copy link

A State class that contains a value class will fail with InstantiationException: java.lang.Class<...> has no zero argument constructor error.

Eg:

@JvmInline
value class MyValueClass(private val num: Int) {
    companion object {
        val Default: MyValueClass = MyValueClass(1)
    }
}

data class Temp(val x: String = "test", val y: MyValueClass = MyValueClass.Default): MavericksState
@brentwatson
Copy link
Author

Looks like this might actually be a Kotlin Compiler bug. Looking at the bytecode, the default no-arg constructor actually isn't being generated in this case. I opened a ticket here: https://youtrack.jetbrains.com/issue/KT-64132

A workaround seems to be to simply wrap your value class type in another data class and use that in your State object

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

No branches or pull requests

1 participant