[ANN] ppx_deriving.6.0.2 and ppx_deriving_yojson.3.8.0

I’m sorry, I was testing against the old (working as expected) version of ppx_deriving. OOPS! Sorry sorry. Please disregard my previous comment. But regarding what you wrote above, actually no, the way ppx_deriving.5.2.1 worked, is that if source file is named “foo.bar.buzz.ml”, then the “file path” in the generated code is "Foo.bar.buzz". Which is not a valid module-name, but … there it is.

ETA: here is an example:

  1. file “foo.bar.buzz.ml”
open OUnit2

let printer = fun x -> x

type v = Foo | Bar of int * string | Baz of string [@@deriving show { with_path = true }]
let test_variant ctxt =
  assert_equal ~printer "Foo.Foo"                (show_v Foo);
  assert_equal ~printer "(Foo.Bar (1, \"foo\"))" (show_v (Bar (1, "foo")));
  assert_equal ~printer "(Foo.Baz \"foo\")"      (show_v (Baz "foo"))

let suite = "Test deriving(show)" >::: [
    "test_variant"         >:: test_variant
  ]

let _ = run_test_tt_main suite
;;
print_string (show_v Foo) ;;
  1. command to preprocess and build:
ocamlfind ocamlc -g -custom -package ounit2,ppx_deriving.show -linkpkg -o foobad foo.bar.buzz.ml
  1. output per “-dsource”
open OUnit2
let printer x = x
type v =
  | Foo 
  | Bar of int * string 
  | Baz of string [@@deriving show { with_path = true }]
let rec pp_v :
  Ppx_deriving_runtime.Format.formatter -> v -> Ppx_deriving_runtime.unit =
  ((let open! ((Ppx_deriving_runtime)[@ocaml.warning "-A"]) in
      fun fmt ->
        function
        | Foo ->
            Ppx_deriving_runtime.Format.pp_print_string fmt
              "Foo.bar.buzz.Foo"
        | Bar (a0, a1) ->
            (Ppx_deriving_runtime.Format.fprintf fmt
               "(@[<2>Foo.bar.buzz.Bar (@,";
             ((Ppx_deriving_runtime.Format.fprintf fmt "%d") a0;
              Ppx_deriving_runtime.Format.fprintf fmt ",@ ";
              (Ppx_deriving_runtime.Format.fprintf fmt "%S") a1);
             Ppx_deriving_runtime.Format.fprintf fmt "@,))@]")
        | Baz a0 ->
            (Ppx_deriving_runtime.Format.fprintf fmt
               "(@[<2>Foo.bar.buzz.Baz@ ";
             (Ppx_deriving_runtime.Format.fprintf fmt "%S") a0;
             Ppx_deriving_runtime.Format.fprintf fmt "@])"))
  [@ocaml.warning "-A"])
and show_v : v -> Ppx_deriving_runtime.string =
  fun x -> Ppx_deriving_runtime.Format.asprintf "%a" pp_v x[@@ocaml.warning
                                                             "-32"]
include struct let _ = fun (_ : v) -> () end[@@ocaml.doc "@inline"][@@merlin.hide
                                                                    ]
let test_variant ctxt =
  assert_equal ~printer "Foo.Foo" (show_v Foo);
  assert_equal ~printer "(Foo.Bar (1, \"foo\"))" (show_v (Bar (1, "foo")));
  assert_equal ~printer "(Foo.Baz \"foo\")" (show_v (Baz "foo"))
let suite = "Test deriving(show)" >::: ["test_variant" >:: test_variant]
let _ = run_test_tt_main suite

Notice in pp_v that the “show” of constructor Foo is Foo.bar.buzz.Foo.

ETA: oops, it’s too late here, I’m not thinking straight. Your comment and mine are compatible.

  1. if a file “foo.bar.buzz.cppo.ml” is preprocessed to produce a source file “foo.bar.buzz.ml”
  2. then ppx_deriving.show (v5.2.1) will produce code that uses a file_path “Foo.bar.buzz”. So it does indeed (as you say) ignore the #line directive and go straight to the source-file-name. But if that source-file-name isn’t a valid module-name … too bad! Ha! And this remains the case even if we use “-o yaddayadda.cmo” to output to a different CMO file. Of course, code that wants to use that module has to use the module name Yaddayadda.