Skip to content

Commit f9fa60c

Browse files
JulowGuillaume Petiot
and
Guillaume Petiot
authored
Backport 5.2 build fixes (#2545)
Co-authored-by: Jules Aguillon <[email protected]> Co-authored-by: Guillaume Petiot <[email protected]>
1 parent 6734dfc commit f9fa60c

18 files changed

+324
-58
lines changed

Diff for: CHANGES.md

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ Items marked with an asterisk (\*) are changes that are likely to format
44
existing code differently from the previous release when using the default
55
profile. This started with version 0.26.0.
66

7+
## unreleased
8+
9+
### Changed
10+
11+
- Compatible with OCaml 5.2.0 (#2510, @gpetiot, @Julow)
12+
713
## 0.26.1 (2023-09-15)
814

915
### Changed

Diff for: test/cli/repl_file_errors.t/run.t

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,25 @@ Make sure the locations of errors in repl files are right.
55
$ ocamlformat --repl-file line5.repl
66
ocamlformat: ignoring "line5.repl" (syntax error)
77
File "line5.repl", line 5, characters 12-12:
8-
Error: Syntax error: a toplevel phrase must end with `;;`. expected.
8+
Error: Syntax error: "a toplevel phrase must end with `;;`." expected.
99
[1]
1010

1111
$ ocamlformat --repl-file line6.repl
1212
ocamlformat: ignoring "line6.repl" (syntax error)
1313
File "line6.repl", line 6, characters 12-12:
14-
Error: Syntax error: a toplevel phrase must end with `;;`. expected.
14+
Error: Syntax error: "a toplevel phrase must end with `;;`." expected.
1515
[1]
1616

1717
$ ocamlformat --repl-file line7.repl
1818
ocamlformat: ignoring "line7.repl" (syntax error)
1919
File "line7.repl", line 7, characters 12-12:
20-
Error: Syntax error: a toplevel phrase must end with `;;`. expected.
20+
Error: Syntax error: "a toplevel phrase must end with `;;`." expected.
2121
[1]
2222

2323
$ ocamlformat --repl-file missing_semisemi.repl
2424
ocamlformat: ignoring "missing_semisemi.repl" (syntax error)
2525
File "missing_semisemi.repl", line 2, characters 10-10:
26-
Error: Syntax error: a toplevel phrase must end with `;;`. expected.
26+
Error: Syntax error: "a toplevel phrase must end with `;;`." expected.
2727
[1]
2828

2929
$ ocamlformat --repl-file empty_line_begin.repl

Diff for: test/failing/tests/module.ml.broken-ref

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ ocamlformat: ignoring "tests/module.ml" (syntax error)
22
File "tests/module.ml", line 5, characters 18-22:
33
5 | include Foo with type t := t
44
^^^^
5-
Error: Syntax error: 'end' expected
5+
Error: Syntax error: "end" expected
66
File "tests/module.ml", line 3, characters 15-21:
77
3 | module G = struct
88
^^^^^^
9-
This 'struct' might be unmatched
9+
This "struct" might be unmatched

Diff for: test/failing/tests/nesting.ml.broken-ref

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
ocamlformat: ignoring "tests/nesting.ml" (syntax error)
22
File "tests/nesting.ml", line 35, characters 0-0:
3-
Error: Syntax error: 'end' expected
3+
Error: Syntax error: "end" expected
44
File "tests/nesting.ml", line 1, characters 11-17:
55
1 | module M = struct
66
^^^^^^
7-
This 'struct' might be unmatched
7+
This "struct" might be unmatched

Diff for: test/failing/tests/never_align.ml.broken-ref

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ ocamlformat: ignoring "tests/never_align.ml" (syntax error)
22
File "tests/never_align.ml", line 13, characters 4-5:
33
13 | b
44
^
5-
Error: Syntax error: '}' expected
5+
Error: Syntax error: "}" expected
66
File "tests/never_align.ml", line 11, characters 8-9:
77
11 | let _ = {
88
^
9-
This '{' might be unmatched
9+
This "{" might be unmatched

Diff for: test/failing/tests/ppx_stritem_ext.ml.broken-ref

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ ocamlformat: ignoring "tests/ppx_stritem_ext.ml" (syntax error)
22
File "tests/ppx_stritem_ext.ml", line 10, characters 11-14:
33
10 | module S = sig
44
^^^
5-
Error: Syntax error: struct expected.
5+
Error: Syntax error: "struct" expected.

Diff for: test/unit/test_translation_unit.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ let test_parse_and_format_module_type =
6767
{|test_unit: ignoring "<test>" (syntax error)
6868

6969
File "<test>", line 1, characters 3-3:
70-
Error: Syntax error: 'end' expected
70+
Error: Syntax error: "end" expected
7171
File "<test>", line 1, characters 0-3:
72-
This 'sig' might be unmatched
72+
This "sig" might be unmatched
7373
|}
7474
)
7575
; make_test "full sig"

Diff for: vendor/ocaml-common/location.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ let print_updating_num_loc_lines ppf f arg =
147147
pp_set_formatter_out_functions ppf out_functions
148148

149149
let setup_colors () =
150-
Misc.Color.setup !Clflags.color
150+
Misc.Style.setup !Clflags.color
151151

152152
(******************************************************************************)
153153
(* Printing locations, e.g. 'File "foo.ml", line 3, characters 10-12' *)

Diff for: vendor/ocaml-common/syntaxerr.ml

+9-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@
1515

1616
(* Auxiliary type for reporting syntax errors *)
1717

18+
type invalid_package_type =
19+
| Parameterized_types
20+
| Constrained_types
21+
| Private_types
22+
| Not_with_type
23+
| Neither_identifier_nor_with_type
24+
1825
type error =
1926
Unclosed of Location.t * string * Location.t * string
2027
| Expecting of Location.t * string
@@ -23,7 +30,7 @@ type error =
2330
| Variable_in_scope of Location.t * string
2431
| Other of Location.t
2532
| Ill_formed_ast of Location.t * string
26-
| Invalid_package_type of Location.t * string
33+
| Invalid_package_type of Location.t * invalid_package_type
2734
| Removed_string_set of Location.t
2835

2936
exception Error of error
@@ -37,7 +44,7 @@ let location_of_error = function
3744
| Not_expecting (l, _)
3845
| Ill_formed_ast (l, _)
3946
| Invalid_package_type (l, _)
40-
| Expecting (l, _) -> l
47+
| Expecting (l, _)
4148
| Removed_string_set l -> l
4249

4350

Diff for: vendor/ocaml-common/syntaxerr.mli

+8-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@
2020
2121
*)
2222

23+
type invalid_package_type =
24+
| Parameterized_types
25+
| Constrained_types
26+
| Private_types
27+
| Not_with_type
28+
| Neither_identifier_nor_with_type
29+
2330
type error =
2431
Unclosed of Location.t * string * Location.t * string
2532
| Expecting of Location.t * string
@@ -28,7 +35,7 @@ type error =
2835
| Variable_in_scope of Location.t * string
2936
| Other of Location.t
3037
| Ill_formed_ast of Location.t * string
31-
| Invalid_package_type of Location.t * string
38+
| Invalid_package_type of Location.t * invalid_package_type
3239
| Removed_string_set of Location.t
3340

3441
exception Error of error

Diff for: vendor/parser-extended/parse.ml

+34-11
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ let type_ident = wrap Parser.Incremental.parse_mty_longident
138138
(* Error reporting for Syntaxerr *)
139139
(* The code has been moved here so that one can reuse Pprintast.tyvar *)
140140

141+
module Style = Misc.Style
142+
141143
let prepare_error err =
142144
let open Syntaxerr in
143145
match err with
@@ -146,37 +148,58 @@ let prepare_error err =
146148
~loc:closing_loc
147149
~sub:[
148150
Location.msg ~loc:opening_loc
149-
"This '%s' might be unmatched" opening
151+
"This %a might be unmatched" Style.inline_code opening
150152
]
151-
"Syntax error: '%s' expected" closing
153+
"Syntax error: %a expected" Style.inline_code closing
152154

153155
| Expecting (loc, nonterm) ->
154-
Location.errorf ~loc "Syntax error: %s expected." nonterm
156+
Location.errorf ~loc "Syntax error: %a expected."
157+
Style.inline_code nonterm
155158
| Not_expecting (loc, nonterm) ->
156-
Location.errorf ~loc "Syntax error: %s not expected." nonterm
159+
Location.errorf ~loc "Syntax error: %a not expected."
160+
Style.inline_code nonterm
157161
| Applicative_path loc ->
158162
Location.errorf ~loc
159-
"Syntax error: applicative paths of the form F(X).t \
160-
are not supported when the option -no-app-func is set."
163+
"Syntax error: applicative paths of the form %a \
164+
are not supported when the option %a is set."
165+
Style.inline_code "F(X).t"
166+
Style.inline_code "-no-app-func"
161167
| Variable_in_scope (loc, var) ->
162168
Location.errorf ~loc
163169
"In this scoped type, variable %a \
164-
is reserved for the local type %s."
165-
Pprintast.tyvar var var
170+
is reserved for the local type %a."
171+
(Style.as_inline_code Pprintast.tyvar) var
172+
Style.inline_code var
166173
| Other loc ->
167174
Location.errorf ~loc "Syntax error"
168175
| Ill_formed_ast (loc, s) ->
169176
Location.errorf ~loc
170177
"broken invariant in parsetree: %s" s
171-
| Invalid_package_type (loc, s) ->
172-
Location.errorf ~loc "invalid package type: %s" s
178+
| Invalid_package_type (loc, ipt) ->
179+
let invalid ppf ipt = match ipt with
180+
| Syntaxerr.Parameterized_types ->
181+
Format.fprintf ppf "parametrized types are not supported"
182+
| Constrained_types ->
183+
Format.fprintf ppf "constrained types are not supported"
184+
| Private_types ->
185+
Format.fprintf ppf "private types are not supported"
186+
| Not_with_type ->
187+
Format.fprintf ppf "only %a constraints are supported"
188+
Style.inline_code "with type t ="
189+
| Neither_identifier_nor_with_type ->
190+
Format.fprintf ppf
191+
"only module type identifier and %a constraints are supported"
192+
Style.inline_code "with type"
193+
in
194+
Location.errorf ~loc "invalid package type: %a" invalid ipt
173195
| Removed_string_set loc ->
174196
Location.errorf ~loc
175197
"Syntax error: strings are immutable, there is no assignment \
176198
syntax for them.\n\
177199
@{<hint>Hint@}: Mutable sequences of bytes are available in \
178200
the Bytes module.\n\
179-
@{<hint>Hint@}: Did you mean to use 'Bytes.set'?"
201+
@{<hint>Hint@}: Did you mean to use %a?"
202+
Style.inline_code "Bytes.set"
180203
let () =
181204
Location.register_error_of_exn
182205
(function

Diff for: vendor/parser-extended/parser.mly

+5-6
Original file line numberDiff line numberDiff line change
@@ -503,11 +503,11 @@ let package_type_of_module_type pmty =
503503
| Pwith_type (lid, ptyp) ->
504504
let loc = ptyp.ptype_loc in
505505
if ptyp.ptype_params <> [] then
506-
err loc "parametrized types are not supported";
506+
err loc Syntaxerr.Parameterized_types;
507507
if ptyp.ptype_cstrs <> [] then
508-
err loc "constrained types are not supported";
508+
err loc Syntaxerr.Constrained_types;
509509
if ptyp.ptype_private <> Public then
510-
err loc "private types are not supported";
510+
err loc Syntaxerr.Private_types;
511511

512512
(* restrictions below are checked by the 'with_constraint' rule *)
513513
assert (ptyp.ptype_kind = Ptype_abstract);
@@ -519,15 +519,14 @@ let package_type_of_module_type pmty =
519519
in
520520
(lid, ty)
521521
| _ ->
522-
err pmty.pmty_loc "only 'with type t =' constraints are supported"
522+
err pmty.pmty_loc Not_with_type
523523
in
524524
match pmty with
525525
| {pmty_desc = Pmty_ident lid} -> (lid, [], pmty.pmty_attributes)
526526
| {pmty_desc = Pmty_with({pmty_desc = Pmty_ident lid}, cstrs)} ->
527527
(lid, List.map map_cstr cstrs, pmty.pmty_attributes)
528528
| _ ->
529-
err pmty.pmty_loc
530-
"only module type identifier and 'with type' constraints are supported"
529+
err pmty.pmty_loc Neither_identifier_nor_with_type
531530

532531
let mk_directive_arg ~loc k =
533532
{ pdira_desc = k;

Diff for: vendor/parser-shims/dune

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
(library
22
(name parser_shims)
33
(public_name ocamlformat-lib.parser_shims)
4+
(flags
5+
(:standard -w -37 -w -38))
46
(libraries compiler-libs.common))

0 commit comments

Comments
 (0)