Skip to content

Deriver: Clash between type constructors and type parameters #399

@Niols

Description

@Niols

For instance:

type foo = int [@@deriving qcheck]
type 'foo s = ('foo * foo) [@@deriving qcheck]
type t = float s [@@deriving qcheck]

will yield something in the lines of:

Error: Signature mismatch:
       ...
       Values do not match:
         val gen : (float * float) QCheck.Gen.t
       is not included in
         val gen : t QCheck.Gen.t
       The type
         (float * float) QCheck.Gen.t = Random.State.t -> float * float
       is not compatible with the type
         t QCheck.Gen.t = Random.State.t -> t
       Type float * float is not compatible with type t = float * a
       Type float is not compatible with type a

My guess is that it is because ppx_deriving_qcheck derives a variable name deterministically from the name of the type constructor or type parameter, both of which are foo in this example.

An easy patch is to add a prefix to disambiguate (eg. var_foo vs foo); a clean patch is to rely on Ppx_deriving's quoters. This is very much a corner case, and it would be rather ugly OCaml to do this in the first place, so I'm not even sure it is worth fixing; I only discovered it while testing my own deriver (that also doesn't use a quoter) for this precise corner case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions