Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/top/compat_top.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 16 additions & 6 deletions lib/top/mdx_top.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <expr> *)
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 =
Expand All @@ -187,10 +192,10 @@ module Rewrite = struct
(* Rewrite Async.Defered.t expressions to
Async.Thread_safe.block_on_async_exn (fun () -> <expr>). *)
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
Expand Down Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion test/bin/mdx-test/expect/warnings/test-case.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand All @@ -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
Expand Down
Loading