Skip to content

Commit 32ee827

Browse files
committed
Fix bad misalignment of short-syntax functor arguments
1 parent 3815e54 commit 32ee827

File tree

13 files changed

+66
-20
lines changed

13 files changed

+66
-20
lines changed

lib/Fmt_ast.ml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4162,10 +4162,19 @@ and fmt_module c ctx ?rec_ ?epi ?(can_sparse = false) keyword ?(eqty = "=")
41624162
let ext = attrs.attrs_extension in
41634163
let blk_t =
41644164
Option.value_map xmty ~default:empty ~f:(fun xmty ->
4165+
let break_before_ty =
4166+
match xmty.ast.pmty_desc with
4167+
(* Break functor types that use the short syntax and avoid
4168+
misaligning the parameter types. *)
4169+
| Pmty_functor (Pfunctorty_unnamed _, _) -> break 1 2
4170+
| _ -> str " "
4171+
in
41654172
let blk = fmt_module_type ?rec_ c xmty in
4173+
let pro =
4174+
str " " $ str eqty $ opt blk.pro (fun pro -> break_before_ty $ pro)
4175+
in
41664176
{ blk with
4167-
pro=
4168-
Some (str " " $ str eqty $ opt blk.pro (fun pro -> str " " $ pro))
4177+
pro= Some pro
41694178
; psp= fmt_if (Option.is_none blk.pro) (break 1 2) $ blk.psp } )
41704179
in
41714180
let blk_b = Option.value_map xbody ~default:empty ~f:(fmt_module_expr c) in

test/passing/refs.ahrefs/functor-414.ml.ref

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,14 @@ module M = struct
143143
end
144144

145145
module Simple : (Parameters with type update_result := state) -> S = M
146+
module Simple : S -> Parameters with type update_result := state = M
146147

147-
module Left_variadic : (Parameters
148-
with type update_result := state * left array)
148+
module Left_variadic :
149+
(Parameters with type update_result := state * left array)
149150
-> S =
150151
M
152+
module Left_variadic : S ->
153+
Parameters with type update_result := state * left array =
154+
M
151155

152156
module N : S with module type T = (U -> U) = struct end

test/passing/refs.ahrefs/functor.ml.ref

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,14 @@ module M = struct
143143
end
144144

145145
module Simple : (Parameters with type update_result := state) -> S = M
146+
module Simple : S -> Parameters with type update_result := state = M
146147

147-
module Left_variadic : (Parameters
148-
with type update_result := state * left array)
148+
module Left_variadic :
149+
(Parameters with type update_result := state * left array)
149150
-> S =
150151
M
152+
module Left_variadic : S ->
153+
Parameters with type update_result := state * left array =
154+
M
151155

152156
module N : S with module type T = (U -> U) = struct end

test/passing/refs.ahrefs/functor.mli.ref

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ end) : S
44

55
module Simple : (Parameters with type update_result := state) -> S
66

7-
module Left_variadic : (Parameters
8-
with type update_result := state * left array)
7+
module Left_variadic :
8+
(Parameters with type update_result := state * left array)
99
-> S

test/passing/refs.default/functor-414.ml.ref

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,15 @@ module M = struct
123123
end
124124

125125
module Simple : (Parameters with type update_result := state) -> S = M
126+
module Simple : S -> Parameters with type update_result := state = M
126127

127-
module Left_variadic : (Parameters
128-
with type update_result := state * left array)
128+
module Left_variadic :
129+
(Parameters with type update_result := state * left array)
129130
-> S =
130131
M
131132

133+
module Left_variadic : S ->
134+
Parameters with type update_result := state * left array =
135+
M
136+
132137
module N : S with module type T = (U -> U) = struct end

test/passing/refs.default/functor.ml.ref

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,15 @@ module M = struct
123123
end
124124

125125
module Simple : (Parameters with type update_result := state) -> S = M
126+
module Simple : S -> Parameters with type update_result := state = M
126127

127-
module Left_variadic : (Parameters
128-
with type update_result := state * left array)
128+
module Left_variadic :
129+
(Parameters with type update_result := state * left array)
129130
-> S =
130131
M
131132

133+
module Left_variadic : S ->
134+
Parameters with type update_result := state * left array =
135+
M
136+
132137
module N : S with module type T = (U -> U) = struct end

test/passing/refs.default/functor.mli.ref

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ end) : S
44

55
module Simple : (Parameters with type update_result := state) -> S
66

7-
module Left_variadic : (Parameters
8-
with type update_result := state * left array)
7+
module Left_variadic :
8+
(Parameters with type update_result := state * left array)
99
-> S

test/passing/refs.janestreet/functor-414.ml.ref

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,5 +122,7 @@ module M = struct
122122
end
123123

124124
module Simple : (Parameters with type update_result := state) -> S = M
125+
module Simple : S -> Parameters with type update_result := state = M
125126
module Left_variadic : (Parameters with type update_result := state * left array) -> S = M
127+
module Left_variadic : S -> Parameters with type update_result := state * left array = M
126128
module N : S with module type T = (U -> U) = struct end

test/passing/refs.janestreet/functor.ml.ref

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,5 +122,7 @@ module M = struct
122122
end
123123

124124
module Simple : (Parameters with type update_result := state) -> S = M
125+
module Simple : S -> Parameters with type update_result := state = M
125126
module Left_variadic : (Parameters with type update_result := state * left array) -> S = M
127+
module Left_variadic : S -> Parameters with type update_result := state * left array = M
126128
module N : S with module type T = (U -> U) = struct end

test/passing/refs.ocamlformat/functor-414.ml.ref

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,15 @@ end
159159

160160
module Simple : (Parameters with type update_result := state) -> S = M
161161

162-
module Left_variadic : (Parameters
163-
with type update_result := state * left array)
162+
module Simple : S -> Parameters with type update_result := state = M
163+
164+
module Left_variadic :
165+
(Parameters with type update_result := state * left array)
164166
-> S =
165167
M
166168

169+
module Left_variadic : S ->
170+
Parameters with type update_result := state * left array =
171+
M
172+
167173
module N : S with module type T = (U -> U) = struct end

0 commit comments

Comments
 (0)