diff --git a/lib/top/compat_top.mli b/lib/top/compat_top.mli index 426d1b9e..7544eeab 100644 --- a/lib/top/compat_top.mli +++ b/lib/top/compat_top.mli @@ -8,7 +8,11 @@ val find_type : Env.t -> Location.t -> Longident.t -> Path.t * Types.type_declaration val find_constructor : +#if OCAML_VERSION < (5, 4, 0) Env.t -> Location.t -> Longident.t -> Types.constructor_description +#else + Env.t -> Location.t -> Longident.t -> Data_types.constructor_description +#endif val find_module : Env.t -> Location.t -> Longident.t -> Path.t * Types.module_declaration diff --git a/lib/top/mdx_top.ml b/lib/top/mdx_top.ml index b64c1bf8..51f9115e 100644 --- a/lib/top/mdx_top.ml +++ b/lib/top/mdx_top.ml @@ -169,11 +169,16 @@ module Rewrite = struct mutable preload : string option; } +#if OCAML_VERSION < (5, 4, 0) + let ldot (a, b) = Longident.Ldot(a, b) +#else + let ldot (a, b) = Longident.Ldot(Location.mknoloc a, Location.mknoloc b) +#endif (* Rewrite Lwt.t expressions to Lwt_main.run *) let lwt = - let typ = Longident.(Ldot (Lident "Lwt", "t")) in - let runner = Longident.(Ldot (Lident "Lwt_main", "run")) in - let witness = Longident.(Ldot (Lident "Lwt", "return")) in + let typ = Longident.(ldot (Lident "Lwt", "t")) in + let runner = Longident.(ldot (Lident "Lwt_main", "run")) in + let witness = Longident.(ldot (Lident "Lwt", "return")) in let preload = Some "lwt.unix" in let open Ast_helper in let rewrite loc e = @@ -187,10 +192,10 @@ module Rewrite = struct (* Rewrite Async.Defered.t expressions to Async.Thread_safe.block_on_async_exn (fun () -> ). *) let async = - let typ = Longident.(Ldot (Ldot (Lident "Async", "Deferred"), "t")) in + let typ = Longident.(ldot (ldot (Lident "Async", "Deferred"), "t")) in let runner = Longident.( - Ldot (Ldot (Lident "Async", "Thread_safe"), "block_on_async_exn")) + ldot (ldot (Lident "Async", "Thread_safe"), "block_on_async_exn")) in let witness = runner in let preload = None in @@ -453,7 +458,12 @@ let add_directive ~name ~doc kind = let s = match lid with | Longident.Lident s -> s - | Longident.Ldot (_, s) -> s + | Longident.Ldot (_, s) -> +#if OCAML_VERSION < (5, 4, 0) + s +#else + s.txt +#endif | Longident.Lapply _ -> Format.printf "Invalid path %a@." Printtyp.longident lid; raise Exit diff --git a/test/bin/mdx-test/expect/warnings/test-case.md b/test/bin/mdx-test/expect/warnings/test-case.md index 60b1857d..b1530c16 100644 --- a/test/bin/mdx-test/expect/warnings/test-case.md +++ b/test/bin/mdx-test/expect/warnings/test-case.md @@ -19,7 +19,7 @@ y Either bind these labels explicitly or add '; _' to the pattern. ``` -```ocaml version>=4.12 +```ocaml version>=4.12,version<5.4 [@@@warning "+9"] let x { x } = x ``` @@ -30,6 +30,17 @@ y Either bind these labels explicitly or add '; _' to the pattern. ``` +```ocaml version>=5.4 +[@@@warning "+9"] +let x { x } = x +``` +```mdx-error +Line 2, characters 9-14: +Warning 9 [missing-record-field-pattern]: the following labels are not bound + in this record pattern: y. + Either bind these labels explicitly or add ; _ to the pattern. +``` + Test against some false positives: ```ocaml