Open Invizory opened 1 year ago
Thanks for the report!
Ping @vch9 - I think we are not handling type constructors correctly in is_rec_typ
Thanks for the report again.
Definitely a problem in is_rec_type
, t
should not be considered recursive (in the latter). I will try to have a look
I think the deriver fails on a very much simpler example: type t = t list
. I did not consider the rectypes
flag as I just discovered it :sweat_smile:.
It creates:
let gen = QCheck.Gen.list gen
let arb = QCheck.make @@ gen
Should we be smarter than:
let rec gen = QCheck.Gen.list gen
let arb = QCheck.make @@ gen
?
IMO using rectypes
is a cornercase that we don't necessarily have to support (I read the report as trying to use it as a workaround).
I suggest prioritising the reported case type t = Box of t list
of "vanilla OCaml usage" where it seems we don't identify an occurrence of t
as recursive when it is a type parameter to a type constructor such as list
(or option
or result
...) :thinking:
In trying out a potential workaround I just experienced the following error variant:
utop # #require "ppx_deriving";;
utop # #require "ppx_deriving_qcheck";;
utop # type t = Box of foo
and foo = t list [@@deriving qcheck];;
Error: Unbound value n
I'm not sure but I think this is related. I'm having an issue where I can't derive a generator in a mutually recursive datatype with equivalent constructors:
[@deriving qcheck]
type conflicting_constructor =
| A
| B(conflicting_constructor2)
and conflicting_constructor2 =
| B(conflicting_constructor)
| C;
Error: This expression has type
conflicting_constructor QCheck.Gen.t =
Random.State.t -> conflicting_constructor
but an expression was expected of type
conflicting_constructor2 QCheck.Gen.t =
Random.State.t -> conflicting_constructor2
Type conflicting_constructor is not compatible with type
conflicting_constructor2
Minimal reproducible example:
ppx_deriving_qcheck
produces the following generator with unboundgen
:This trick (given
-rectypes
is enabled) make it derive the following generator:However, this generatior is non-terminating.