Skip to content

Commit 3815e54

Browse files
committed
Missing parens in module type (M with type ..) -> N
Fix the parenthesing rules for `with type` inside functors and functors inside `with type`.
1 parent cb01918 commit 3815e54

File tree

15 files changed

+153
-44
lines changed

15 files changed

+153
-44
lines changed

lib/Ast.ml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1914,12 +1914,9 @@ end = struct
19141914
Mty.has_trailing_attributes mty
19151915
||
19161916
match (ctx, mty.pmty_desc) with
1917-
| Mty {pmty_desc= Pmty_with _; _}, Pmty_with _ -> true
1918-
| ( Mty
1919-
{ pmty_desc=
1920-
Pmty_with (lhs, _) | Pmty_functor (Pfunctorty_unnamed lhs, _)
1921-
; _ }
1922-
, Pmty_functor _ )
1917+
| Mty {pmty_desc= Pmty_with _; _}, (Pmty_with _ | Pmty_functor _) -> true
1918+
| ( Mty {pmty_desc= Pmty_functor (Pfunctorty_unnamed lhs, _); _}
1919+
, (Pmty_with _ | Pmty_functor _) )
19231920
when lhs == mty ->
19241921
true
19251922
| _ -> false

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,21 @@ functor
132132

133133
module M : (_ : X) -> X = Y
134134

135-
[@@@ocamlformat "break-struct=natural"]
135+
module M = struct
136+
[@@@ocamlformat "break-struct=natural"]
136137

137-
module M = F (struct type t end : sig type t end)
138+
module M = F (struct type t end : sig type t end)
138139

139-
module M = struct type t end
140+
module M = struct type t end
140141

141-
module type S = sig type t end
142+
module type S = sig type t end
143+
end
144+
145+
module Simple : (Parameters with type update_result := state) -> S = M
146+
147+
module Left_variadic : (Parameters
148+
with type update_result := state * left array)
149+
-> S =
150+
M
151+
152+
module N : S with module type T = (U -> U) = struct end

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,21 @@ functor
132132

133133
module M : (_ : X) -> X = Y
134134

135-
[@@@ocamlformat "break-struct=natural"]
135+
module M = struct
136+
[@@@ocamlformat "break-struct=natural"]
136137

137-
module M = F (struct type t end : sig type t end)
138+
module M = F (struct type t end : sig type t end)
138139

139-
module M = struct type t end
140+
module M = struct type t end
140141

141-
module type S = sig type t end
142+
module type S = sig type t end
143+
end
144+
145+
module Simple : (Parameters with type update_result := state) -> S = M
146+
147+
module Left_variadic : (Parameters
148+
with type update_result := state * left array)
149+
-> S =
150+
M
151+
152+
module N : S with module type T = (U -> U) = struct end
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
module F (* test *) (M : sig
22
type t
33
end) : S
4+
5+
module Simple : (Parameters with type update_result := state) -> S
6+
7+
module Left_variadic : (Parameters
8+
with type update_result := state * left array)
9+
-> S

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,20 @@ functor
113113

114114
module M : (_ : X) -> X = Y
115115

116-
[@@@ocamlformat "break-struct=natural"]
116+
module M = struct
117+
[@@@ocamlformat "break-struct=natural"]
117118

118-
module M = F (struct type t end : sig type t end)
119-
module M = struct type t end
119+
module M = F (struct type t end : sig type t end)
120+
module M = struct type t end
120121

121-
module type S = sig type t end
122+
module type S = sig type t end
123+
end
124+
125+
module Simple : (Parameters with type update_result := state) -> S = M
126+
127+
module Left_variadic : (Parameters
128+
with type update_result := state * left array)
129+
-> S =
130+
M
131+
132+
module N : S with module type T = (U -> U) = struct end

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,20 @@ functor
113113

114114
module M : (_ : X) -> X = Y
115115

116-
[@@@ocamlformat "break-struct=natural"]
116+
module M = struct
117+
[@@@ocamlformat "break-struct=natural"]
117118

118-
module M = F (struct type t end : sig type t end)
119-
module M = struct type t end
119+
module M = F (struct type t end : sig type t end)
120+
module M = struct type t end
120121

121-
module type S = sig type t end
122+
module type S = sig type t end
123+
end
124+
125+
module Simple : (Parameters with type update_result := state) -> S = M
126+
127+
module Left_variadic : (Parameters
128+
with type update_result := state * left array)
129+
-> S =
130+
M
131+
132+
module N : S with module type T = (U -> U) = struct end
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
module F (* test *) (M : sig
22
type t
33
end) : S
4+
5+
module Simple : (Parameters with type update_result := state) -> S
6+
7+
module Left_variadic : (Parameters
8+
with type update_result := state * left array)
9+
-> S

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,17 @@ functor
110110

111111
module M : (_ : X) -> X = Y
112112

113-
[@@@ocamlformat "break-struct=natural"]
113+
module M = struct
114+
[@@@ocamlformat "break-struct=natural"]
114115

115-
module M = F (
116-
struct type t end : sig type t end)
116+
module M = F (
117+
struct type t end : sig type t end)
117118

118-
module M = struct type t end
119+
module M = struct type t end
119120

120-
module type S = sig type t end
121+
module type S = sig type t end
122+
end
123+
124+
module Simple : (Parameters with type update_result := state) -> S = M
125+
module Left_variadic : (Parameters with type update_result := state * left array) -> S = M
126+
module N : S with module type T = (U -> U) = struct end

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,17 @@ functor
110110

111111
module M : (_ : X) -> X = Y
112112

113-
[@@@ocamlformat "break-struct=natural"]
113+
module M = struct
114+
[@@@ocamlformat "break-struct=natural"]
114115

115-
module M = F (
116-
struct type t end : sig type t end)
116+
module M = F (
117+
struct type t end : sig type t end)
117118

118-
module M = struct type t end
119+
module M = struct type t end
119120

120-
module type S = sig type t end
121+
module type S = sig type t end
122+
end
123+
124+
module Simple : (Parameters with type update_result := state) -> S = M
125+
module Left_variadic : (Parameters with type update_result := state * left array) -> S = M
126+
module N : S with module type T = (U -> U) = struct end
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
module F (* test *) (M : sig
22
type t
33
end) : S
4+
5+
module Simple : (Parameters with type update_result := state) -> S
6+
module Left_variadic : (Parameters with type update_result := state * left array) -> S

0 commit comments

Comments
 (0)