Skip to content

Commit f7da780

Browse files
authored
Merge pull request #330 from emillon/413-compat
4.13 compatibility
2 parents f562309 + 6222b81 commit f7da780

File tree

5 files changed

+48
-21
lines changed

5 files changed

+48
-21
lines changed

CHANGES.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
### unreleased
2+
3+
#### Added
4+
5+
- Support for OCaml 4.13 (#330, @emillon)
6+
7+
#### Changed
8+
9+
#### Deprecated
10+
11+
#### Removed
12+
13+
#### Fixed
14+
15+
#### Security
16+
117
### 1.10.0
218

319
#### Added

lib/top/compat_top.ml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,3 +386,10 @@ let top_directive_require pkg =
386386
#else
387387
Parsetree.Ptop_dir ("require", Pdir_string pkg)
388388
#endif
389+
390+
let ctype_is_equal =
391+
#if OCAML_VERSION >= (4, 13, 0)
392+
Ctype.is_equal
393+
#else
394+
Ctype.equal
395+
#endif

lib/top/compat_top.mli

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,6 @@ val top_directive_name : Parsetree.toplevel_phrase -> string option
105105

106106
val top_directive_require : string -> Parsetree.toplevel_phrase
107107
(** [top_directive require "pkg"] builds the AST for [#require "pkg"] *)
108+
109+
val ctype_is_equal :
110+
Env.t -> bool -> Types.type_expr list -> Types.type_expr list -> bool

lib/top/mdx_top.ml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,11 @@ let show_exception () =
453453
reg_show_prim "show_exception"
454454
(fun env loc id lid ->
455455
let desc = Compat_top.find_constructor env loc lid in
456-
if not (Ctype.equal env true [ desc.cstr_res ] [ Predef.type_exn ]) then
457-
raise Not_found;
456+
if
457+
not
458+
(Compat_top.ctype_is_equal env true [ desc.cstr_res ]
459+
[ Predef.type_exn ])
460+
then raise Not_found;
458461
let ret_type =
459462
if desc.cstr_generalized then Some Predef.type_exn else None
460463
in
@@ -611,9 +614,10 @@ let init ~verbose:v ~silent:s ~verbose_findlib ~directives ~packages ~predicates
611614
Topfind.add_predicates predicates;
612615
(* [require] directive is overloaded to toggle the [errors] reference when
613616
an exception is raised. *)
614-
Hashtbl.add Toploop.directive_table "require"
617+
Toploop.add_directive "require"
615618
(Toploop.Directive_string
616-
(fun s -> protect Topfind.load_deeply (in_words s)));
619+
(fun s -> protect Topfind.load_deeply (in_words s)))
620+
{ Toploop.section = "Loading code"; doc = "Load an ocamlfind package" };
617621
let t = { verbose = v; silent = s; verbose_findlib } in
618622
show ();
619623
show_val ();
Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,31 @@
11
No warning is printed by default:
22

33
```ocaml
4-
let () =
5-
let f ~x:() = () in
6-
f ();;
7-
let x = 4
4+
type p = { x : int ; y : int }
5+
6+
let x { x } = x
87
```
98

109
Warning attributes must be set to print them:
1110

1211
```ocaml version<4.12
13-
[@@@warning "+6"]
14-
let () =
15-
let f ~x:() = () in
16-
f ();;
17-
let x = 4
12+
[@@@warning "+9"]
13+
let x { x } = x
1814
```
1915
```mdx-error
2016
...
21-
Warning 6: label x was omitted in the application of this function.
17+
Warning 9: the following labels are not bound in this record pattern:
18+
y
19+
Either bind these labels explicitly or add '; _' to the pattern.
2220
```
2321

2422
```ocaml version>=4.12
25-
[@@@warning "+6"]
26-
let () =
27-
let f ~x:() = () in
28-
f ();;
29-
let x = 4
23+
[@@@warning "+9"]
24+
let x { x } = x
3025
```
3126
```mdx-error
32-
Line 4, characters 5-6:
33-
Warning 6 [labels-omitted]: label x was omitted in the application of this function.
27+
Line 2, characters 9-14:
28+
Warning 9 [missing-record-field-pattern]: the following labels are not bound in this record pattern:
29+
y
30+
Either bind these labels explicitly or add '; _' to the pattern.
3431
```

0 commit comments

Comments
 (0)