Arb.bind<T>() calls the incorrect constructor #1487
Labels
bug 🐛
Issues that report a problem or error in the code.
good-first-issue 👶
Suitable for newcomers looking to contribute to the project.
property-testing 📏
Related to the property testing mechanisms within the testing framework.
Milestone
Which version of Kotest are you using
4.0.6
Description
Kotest's
Arb.bind<T>()
calls the incorrect constructor here:kotest/kotest-property/src/jvmMain/kotlin/io/kotest/property/arbitrary/jvmbind.kt
Line 20 in befa71c
The first constructor returned might be the primaryConstructor, but may not be. Also the set of inputs is derived directly from the primaryConstructor in the code before it. This bug is particularly irritating when mixing Kotest and kotlinx.serialization, because kotlinx.serialization adds a secondary constructor.
Solution
Replace the above line with
kclass.primaryConstructor!!.call(*values.toTypeArray())
and add some documentation stating thatArb.bind<T>()
requiresT
to be a class (the code checks if it's a data class but technically this is not required) with a primaryConstructor, and that this method will always call the primaryConstructor.The text was updated successfully, but these errors were encountered: