Skip to content

Deriving for a module with the same name as a standard library module #57

@khooyp

Description

@khooyp

In ppx_deriving 2.2., it was possible to apply @@deriving on a module that happens to have the same name as a standard library module, e.g.:

module List = struct
    type 'a t = [`Cons of 'a | `Nil] [@@deriving show]
end
type 'a t = 'a List.t option [@@deriving show]

However, this results in an error in ppx_deriving 3.0:

ocamlfind ocamlc -c -package 'ppx_deriving.std' test.ml
File "test.ml", line 4, characters 0-46:
Error: Unbound value List.pp

Looking at the output of ppx_tools/rewriter, it appears that Ppx_deriving_runtime.List is shadowing the user-defined List module:

module List = struct ... end
let rec pp : ... =
  ((let open! Ppx_deriving_runtime in
      fun poly_a  ->
        fun fmt  ->
          function
          | None  -> Format.pp_print_string fmt "None"
          | Some x ->
              (Format.pp_print_string fmt "(Some ";
               (List.pp (fun fmt  -> poly_a fmt) fmt) x;
               Format.pp_print_string fmt ")"))[@ocaml.warning "-A"])
and ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions