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

Arb.bind<T>() calls the incorrect constructor #1487

Closed
sgarfinkel opened this issue Jun 4, 2020 · 1 comment
Closed

Arb.bind<T>() calls the incorrect constructor #1487

sgarfinkel opened this issue Jun 4, 2020 · 1 comment
Assignees
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

Comments

@sgarfinkel
Copy link

Which version of Kotest are you using
4.0.6

Description
Kotest's Arb.bind<T>() calls the incorrect constructor here:

kclass.constructors.first().call(*values.toTypedArray())

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 that Arb.bind<T>() requires T 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.

@sksamuel sksamuel added bug 🐛 Issues that report a problem or error in the code. property-testing 📏 Related to the property testing mechanisms within the testing framework. labels Jun 4, 2020
@LeoColman LeoColman added the good-first-issue 👶 Suitable for newcomers looking to contribute to the project. label Jun 5, 2020
@sksamuel sksamuel added this to the 4.1 milestone Jun 6, 2020
@sksamuel sksamuel mentioned this issue Jun 6, 2020
33 tasks
@sksamuel sksamuel self-assigned this Jun 6, 2020
@sksamuel
Copy link
Member

sksamuel commented Jun 6, 2020

Fixed in master.

@sksamuel sksamuel closed this as completed Jun 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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.
Projects
None yet
Development

No branches or pull requests

3 participants