Skip to content

Commit edfb3d6

Browse files
Port to OCaml 5.1 (#435)
Co-authored-by: Kate <[email protected]>
1 parent f9941da commit edfb3d6

File tree

5 files changed

+31
-16
lines changed

5 files changed

+31
-16
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#### Added
44

5+
- Make MDX compatible with OCaml 5.1 (#435, @polytypic and @kit-ty-kate)
6+
57
#### Changed
68

79
#### Deprecated

lib/top/compat_top.ml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,3 +264,19 @@ let redirect_directive directive =
264264
| "untrace_all" -> mdx_untrace_all
265265
#endif
266266
| v -> v
267+
268+
let rec get_id_in_path = function
269+
| Path.Pident id -> id
270+
| Path.Pdot (p, _) -> get_id_in_path p
271+
| Path.Papply (_, p) -> get_id_in_path p
272+
#if OCAML_VERSION >= (5, 1, 0)
273+
| Path.Pextra_ty (p, _) -> get_id_in_path p
274+
#endif
275+
276+
let get_id_opt = function
277+
| Path.Pident id -> Some id
278+
| Path.Pdot _ -> None
279+
| Path.Papply _ -> None
280+
#if OCAML_VERSION >= (5, 1, 0)
281+
| Path.Pextra_ty _ -> None
282+
#endif

lib/top/compat_top.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,5 @@ val execute_phrase :
6767

6868
(* If the directive has to be intercepted, this function will return the new name of the directive *)
6969
val redirect_directive : string -> string
70+
val get_id_in_path : Path.t -> Ident.t
71+
val get_id_opt : Path.t -> Ident.t option

lib/top/mdx_top.ml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,6 @@ module Rewrite = struct
214214
| _ -> path)
215215
| _ -> path
216216

217-
let rec get_id_in_path = function
218-
| Path.Pident id -> id
219-
| Path.Pdot (p, _) -> get_id_in_path p
220-
| Path.Papply (_, p) -> get_id_in_path p
221-
222217
let is_persistent_value env longident =
223218
let is_persistent_path p = Ident.persistent (get_id_in_path p) in
224219
try is_persistent_path (fst (Compat_top.lookup_value longident env))
@@ -701,9 +696,9 @@ let rec save_summary acc s =
701696
~module_:(fun summary id ~present ->
702697
match present with true -> add summary id | false -> acc)
703698
~open_:(fun summary x ->
704-
match x with
705-
| Pident id -> add summary id
706-
| Pdot _ | Papply _ -> default_case summary)
699+
match get_id_opt x with
700+
| Some id -> add summary id
701+
| None -> default_case summary)
707702
~class_:add ~functor_arg:add ~extension:add
708703
~empty:(fun () -> acc)
709704
~constraints:default_case ~cltype:default_case ~modtype:default_case

test/bin/mdx-test/expect/errors/test-case.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,6 @@ Error: This expression has type string but an expression was expected of type
5353
int
5454
```
5555

56-
```ocaml version>=4.08
57-
# let x =
58-
1 + "42";;
59-
Line 2, characters 7-11:
60-
Error: This expression has type string but an expression was expected of type
61-
int
62-
```
63-
6456
```ocaml non-deterministic=output
6557
# raise Not_found;;
6658
Exception: Not_found.
@@ -71,3 +63,11 @@ Exception: Not_found.
7163
first
7264
Exception: Failure "second".
7365
```
66+
67+
```ocaml version>=4.08
68+
# let x =
69+
1 + "42";;
70+
Line 2, characters 7-11:
71+
Error: This expression has type string but an expression was expected of type
72+
int
73+
```

0 commit comments

Comments
 (0)