EvidentSolutions / dalesbred

Dalesbred - a database access library for Java
https://dalesbred.org
MIT License
54 stars 15 forks source link

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

Open komu opened 1 year ago

komu commented 1 year ago

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.