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

Dalesbred should call constructor-impls of Kotlin value classes #53

Open
komu opened this issue Jan 27, 2023 · 0 comments
Open

Dalesbred should call constructor-impls of Kotlin value classes #53

komu opened this issue Jan 27, 2023 · 0 comments

Comments

@komu
Copy link
Member

komu commented Jan 27, 2023

Consider the following:

class Foo(val b: Bar)

@JvmInline
value class Bar(val x: Int) {
    init {
        require(x > 0)
    }
}

Since Bar is an inline value class, it is represented as an unboxed integer. When Dalesbred instantiates Foo it doesn't consult Kotlin's metadata and will pass the integer it receives from database directly to the Foo's constructor. If there is a non-positive number in the database, the require-call will not be made and exception will not be thrown.

Kotlin does generate a static constructor-impl -method for Bar that we could call to make sure that init-block will be called, but first we'd need to parse Kotlin metadata to detect the situation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant