jqwik icon indicating copy to clipboard operation
jqwik copied to clipboard

ListArbitrary<T> providers are not selected to resolve List<T> parameters

Open lmartelli opened this issue 1 year ago • 1 comments

Testing Problem

A @Provide method in a domain that returns a ListArbitrary<Thing> is not used to generate values for a @ForAll List<Thing>. See https://github.com/jqwik-team/jqwik/compare/main...lmartelli:jqwik:ListArbitrary-provider

Suggested Solution

In net.jqwik.engine.properties.DomainContextBaseProviders.MethodBasedArbitraryProvider#arbitraryType() the actual generic type parameter of ListArbitrary<T> is lost when navigating to the implemented interface Arbitrary<T>.

I am not sure if the mapping can be done in the general case, but it seems safe to say that in the case where there is only one generic type parameter in the class and in the interface, it can be propagated.

I will try to do that.

lmartelli avatar May 24 '23 14:05 lmartelli

If you find an easy solution, go ahead.

My recommendation, though: Don't dive too deep into type matching code if there is an easy workaround - just use Arbitrary<List<Thing>> here. There are too many edge cases concerning co- and contravariance that one can easily have one's soul sucked out trying to cover everything. I already lost too many hours of my life in that area :-/

jlink avatar May 25 '23 11:05 jlink

@lmartelli I assume you haven't found a viable solution. Feel free to re-open if I'm wrong.

jlink avatar May 14 '24 11:05 jlink