Skip to content

Commit d664fa2

Browse files
authored
Remove incorrect fmt_expression ~epi mechanism (#2445)
This argument doesn't work similarly to the `~epi` argument of other functions. It meant different things depending on the expression: - `Pexp_match` and `Pexp_apply`: it was similar to `~pro`. - `Pexp_constant`: like the usual `~epi` but was passed a break. - all other cases: it was not used. These rules are now handled in `fmt_args_grouped`, the only place where they made sense. The `~epi` argument is removed. In the first case, the `~pro` argument is used instead. This requires refactoring `fmt_expression` to make sure that every cases use `~pro` exactly once.
1 parent ab3b75b commit d664fa2

8 files changed

+616
-500
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ profile. This started with version 0.26.0.
1616
- Remove trailing space inside a wrapping empty signature (#2443, @Julow)
1717
- Fix extension-point spacing in structures (#2450, @Julow)
1818
- \* Consistent break after string constant argument (#2453, @Julow)
19+
- Fix invalid syntax generated with `ocp-indent-compat` (#2445, @Julow)
1920

2021
## 0.26.1 (2023-09-15)
2122

lib/Fmt_ast.ml

Lines changed: 492 additions & 433 deletions
Large diffs are not rendered by default.

test/passing/dune.inc

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4114,13 +4114,31 @@
41144114
(package ocamlformat)
41154115
(action (diff tests/obuild.ml.err obuild.ml.stderr)))
41164116

4117+
(rule
4118+
(deps tests/.ocamlformat )
4119+
(package ocamlformat)
4120+
(action
4121+
(with-stdout-to ocp_indent_compat-break_colon_after.ml.stdout
4122+
(with-stderr-to ocp_indent_compat-break_colon_after.ml.stderr
4123+
(run %{bin:ocamlformat} --margin-check --ocp-indent-compat --break-colon=after %{dep:tests/ocp_indent_compat.ml})))))
4124+
4125+
(rule
4126+
(alias runtest)
4127+
(package ocamlformat)
4128+
(action (diff tests/ocp_indent_compat-break_colon_after.ml.ref ocp_indent_compat-break_colon_after.ml.stdout)))
4129+
4130+
(rule
4131+
(alias runtest)
4132+
(package ocamlformat)
4133+
(action (diff tests/ocp_indent_compat-break_colon_after.ml.err ocp_indent_compat-break_colon_after.ml.stderr)))
4134+
41174135
(rule
41184136
(deps tests/.ocamlformat )
41194137
(package ocamlformat)
41204138
(action
41214139
(with-stdout-to ocp_indent_compat.ml.stdout
41224140
(with-stderr-to ocp_indent_compat.ml.stderr
4123-
(run %{bin:ocamlformat} --margin-check %{dep:tests/ocp_indent_compat.ml})))))
4141+
(run %{bin:ocamlformat} --margin-check --ocp-indent-compat --break-colon=before %{dep:tests/ocp_indent_compat.ml})))))
41244142

41254143
(rule
41264144
(alias runtest)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--ocp-indent-compat
2+
--break-colon=after
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
(* Bad: unboxing the function type *)
2+
external i : (int -> float[@unboxed]) = "i" "i_nat"
3+
4+
module type M = sig
5+
val action : action
6+
(** Formatting action: input type and source, and output destination. *)
7+
8+
val doc_atrs :
9+
(string Location.loc * payload) list
10+
-> (string Location.loc * bool) list option
11+
* (string Location.loc * payload) list
12+
13+
val transl_modtype_longident
14+
(* from Typemod *) :
15+
(Location.t -> Env.t -> Longident.t -> Path.t) ref
16+
17+
val transl_modtype_longident
18+
(* foooooooooo fooooooooooooo foooooooooooo foooooooooooooo
19+
foooooooooooooo foooooooooooo *) :
20+
(Location.t -> Env.t -> Longident.t -> Path.t) ref
21+
22+
val imported_sets_of_closures_table :
23+
Simple_value_approx.function_declarations option Set_of_closures_id.Tbl.t
24+
25+
type 'a option_decl =
26+
names:string list
27+
-> doc:string
28+
-> section:[`Formatting | `Operational]
29+
-> ?allow_inline:bool
30+
-> (config -> 'a -> config)
31+
-> (config -> 'a)
32+
-> 'a t
33+
34+
val select :
35+
(* The fsevents context *)
36+
env
37+
-> (* Additional file descriptor to select for reading *)
38+
?read_fdl:fd_select list
39+
-> (* Additional file descriptor to select for writing *)
40+
?write_fdl:fd_select list
41+
-> (* Timeout...like Unix.select *)
42+
timeout:float
43+
-> (* The callback for file system events *)
44+
(event list -> unit)
45+
-> unit
46+
47+
val f :
48+
x:t
49+
(** an extremely long comment about [x] that does not fit on the same
50+
line with [x] *)
51+
-> unit
52+
53+
val f :
54+
fooooooooooooooooo:
55+
(fooooooooooooooo
56+
-> fooooooooooooooooooo
57+
-> foooooooooooooo
58+
-> foooooooooooooo * fooooooooooooooooo
59+
-> foooooooooooooooo )
60+
(** an extremely long comment about [x] that does not fit on the same
61+
line with [x] *)
62+
-> unit
63+
end
64+
65+
let ssmap :
66+
(module MapT
67+
with type key = string
68+
and type data = string
69+
and type map = SSMap.map )
70+
=
71+
()
72+
73+
let ssmap :
74+
(module MapT
75+
with type key = string
76+
and type data = string
77+
and type map = SSMap.map )
78+
-> unit
79+
=
80+
()
81+
82+
let long_function_name :
83+
type a. a long_long_type -> a -> a -> a -> wrap_wrap_wrap -> unit
84+
=
85+
fun () -> ()
86+
87+
let add_edge target dep =
88+
if target <> dep then (
89+
Hashtbl.replace edges dep
90+
(target :: (try Hashtbl.find edges dep with Not_found -> [])) ;
91+
Hashtbl.replace edge_count target
92+
(1 + try Hashtbl.find edge_count target with Not_found -> 0) ;
93+
if not (Hashtbl.mem edge_count dep) then Hashtbl.add edge_count dep 0 )

test/passing/tests/ocp_indent_compat.ml

Lines changed: 7 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
[@@@ocamlformat "ocp-indent-compat=true"]
2-
3-
[@@@ocamlformat "break-colon=before"]
4-
51
(* Bad: unboxing the function type *)
62
external i : (int -> float[@unboxed]) = "i" "i_nat"
73

@@ -89,64 +85,10 @@ let long_function_name
8985
=
9086
fun () -> ()
9187

92-
[@@@ocamlformat "ocp-indent-compat=false"]
93-
94-
[@@@ocamlformat "break-colon=after"]
95-
96-
module type M = sig
97-
val transl_modtype_longident (* from Typemod *) :
98-
(Location.t -> Env.t -> Longident.t -> Path.t) ref
99-
100-
val transl_modtype_longident
101-
(* foooooooooo fooooooooooooo foooooooooooo foooooooooooooo
102-
foooooooooooooo foooooooooooo *) :
103-
(Location.t -> Env.t -> Longident.t -> Path.t) ref
104-
105-
val imported_sets_of_closures_table :
106-
Simple_value_approx.function_declarations option Set_of_closures_id.Tbl.t
107-
108-
val select :
109-
(* The fsevents context *)
110-
env
111-
-> (* Additional file descriptor to select for reading *)
112-
?read_fdl:fd_select list
113-
-> (* Additional file descriptor to select for writing *)
114-
?write_fdl:fd_select list
115-
-> (* Timeout...like Unix.select *)
116-
timeout:float
117-
-> (* The callback for file system events *)
118-
(event list -> unit)
119-
-> unit
120-
121-
val f :
122-
x:t
123-
(** an extremely long comment about [x] that does not fit on the
124-
same line with [x] *)
125-
-> unit
126-
127-
val f :
128-
fooooooooooooooooo:
129-
( fooooooooooooooo
130-
-> fooooooooooooooooooo
131-
-> foooooooooooooo
132-
-> foooooooooooooo * fooooooooooooooooo
133-
-> foooooooooooooooo )
134-
(** an extremely long comment about [x] that does not fit on the
135-
same line with [x] *)
136-
-> unit
137-
end
138-
139-
let array_fold_transf (f : numbering -> 'a -> numbering * 'b) n (a : 'a array)
140-
: numbering * 'b array =
141-
match Array.length a with 0 -> (n, [||]) | 1 -> x
142-
143-
let to_clambda_function (id, (function_decl : Flambda.function_declaration))
144-
: Clambda.ufunction =
145-
(* All that we need in the environment, for translating one closure from a
146-
closed set of closures, is the substitutions for variables bound to the
147-
various closures in the set. Such closures will always be ... *)
148-
x
149-
150-
let long_function_name :
151-
type a. a long_long_type -> a -> a -> a -> wrap_wrap_wrap -> unit =
152-
fun () -> ()
88+
let add_edge target dep =
89+
if target <> dep then (
90+
Hashtbl.replace edges dep
91+
(target :: (try Hashtbl.find edges dep with Not_found -> [])) ;
92+
Hashtbl.replace edge_count target
93+
(1 + try Hashtbl.find edge_count target with Not_found -> 0) ;
94+
if not (Hashtbl.mem edge_count dep) then Hashtbl.add edge_count dep 0 )
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
Warning: tests/ocp_indent_compat.ml:138 exceeds the margin
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--ocp-indent-compat
2+
--break-colon=before

0 commit comments

Comments
 (0)