Skip to content

Commit 9136fc1

Browse files
authored
Add missing break between pattern and attribute (#1711)
1 parent dba5921 commit 9136fc1

19 files changed

+98
-82
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
+ Fix normalization of odoc paragraphs (#1695, @gpetiot)
3838
Paragraphs must not be considered for the normalized form. They are only structural and the shape of a docstring organized in paragraphs only depend on linebreaks, which may be changed by the formatting.
3939

40+
+ Add missing break between pattern and attribute (#1711, @gpetiot)
41+
4042
#### Changes
4143

4244
+ Improve the diff of unstable docstrings displayed in error messages (#1654, @gpetiot)

lib/Fmt_ast.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ and fmt_pattern_attributes c xpat k =
913913
| _ -> true )
914914
in
915915
Params.parens_if parens_attr c.conf
916-
(k $ fmt_attributes c ~key:"@" attrs)
916+
(k $ fmt_attributes c ~pre:Space ~key:"@" attrs)
917917

918918
and fmt_pattern ?ext c ?pro ?parens ?(box = false)
919919
({ctx= ctx0; ast= pat} as xpat) =

test/passing/tests/attributes.ml

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
let _ = (function[@warning "-4"] None -> true | _ -> false) None
22

3-
let f (x[@warning ""]) = ()
3+
let f (x [@warning ""]) = ()
44

55
let v = (fun [@inline] x -> x) 1
66

@@ -105,33 +105,33 @@ type u =
105105
[@@deriving something]
106106
[@@doc ["Ut at dolor a eros venenatis maximus ut at nisi."]]
107107

108-
let ((A, B)[@test]) = ()
108+
let ((A, B) [@test]) = ()
109109

110-
let ((lazy a)[@test]) = ()
110+
let ((lazy a) [@test]) = ()
111111

112-
let ((exception a)[@test]) = ()
112+
let ((exception a) [@test]) = ()
113113

114-
let ((B x)[@test]) = ()
114+
let ((B x) [@test]) = ()
115115

116-
let ((`B x)[@test]) = ()
116+
let ((`B x) [@test]) = ()
117117

118-
let (B[@test]) = ()
118+
let (B [@test]) = ()
119119

120-
let (`B[@test]) = ()
120+
let (`B [@test]) = ()
121121

122-
let (B.(A)[@test]) = ()
122+
let (B.(A) [@test]) = ()
123123

124-
let ('x' .. 'z'[@test]) = ()
124+
let ('x' .. 'z' [@test]) = ()
125125

126-
let (#test[@test]) = ()
126+
let (#test [@test]) = ()
127127

128-
let ((module X)[@test]) = ()
128+
let ((module X) [@test]) = ()
129129

130-
let (a[@test]) = ()
130+
let (a [@test]) = ()
131131

132-
let (_[@test]) = ()
132+
let (_ [@test]) = ()
133133

134-
let (""[@test]) = ()
134+
let ("" [@test]) = ()
135135

136136
let _ = f x ~f:(fun [@test] x -> x)
137137

@@ -149,7 +149,7 @@ let f = fun [@test] x y -> ()
149149

150150
let f y = fun [@test] y -> ()
151151

152-
let (f[@test]) = fun y -> fun [@test] y -> ()
152+
let (f [@test]) = fun y -> fun [@test] y -> ()
153153

154154
module type T = sig
155155
class subst :
@@ -318,23 +318,23 @@ let _ =
318318

319319
[@@@a (**b*)]
320320

321-
let (Foo ((A | B)[@attr])) = ()
321+
let (Foo ((A | B) [@attr])) = ()
322322

323-
let ([((A | B)[@attr]); b; c][@attr]) = ()
323+
let ([((A | B) [@attr]); b; c] [@attr]) = ()
324324

325-
let ([|a; (A | B)[@attr]; c|][@attr]) = ()
325+
let ([|a; (A | B) [@attr]; c|] [@attr]) = ()
326326

327-
let {b= (A | B)[@attr]} = ()
327+
let {b= (A | B) [@attr]} = ()
328328

329-
let (`Foo ((`A | `B)[@attr])) = ()
329+
let (`Foo ((`A | `B) [@attr])) = ()
330330

331-
let (A | B)[@attr], (A | B)[@attr] = ()
331+
let (A | B) [@attr], (A | B) [@attr] = ()
332332

333-
let (A | B)[@attr] = ()
333+
let (A | B) [@attr] = ()
334334

335-
let (Foo ((A | B)[@attr]) : (t[@attr])) = ()
335+
let (Foo ((A | B) [@attr]) : (t[@attr])) = ()
336336

337-
let (M.(A | B)[@attr]) = ();;
337+
let (M.(A | B) [@attr]) = ();;
338338

339339
(a_______________________________________________________________________________
340340
[@attr]) ()
@@ -355,3 +355,17 @@ let _ =
355355
let _ =
356356
(try[@ocaml.warning "-4"] bar with _ -> ()) ;
357357
foo
358+
359+
let pp f ({cf_interface; cf_is_objc_block; cf_virtual} [@warning "+9"]) = ()
360+
361+
let pp f
362+
({cf_assign_last_arg; cf_injected_destructor; cf_interface}
363+
[@warning "+9"] ) =
364+
()
365+
366+
let pp f
367+
({ cf_assign_last_arg
368+
; cf_injected_destructor
369+
; cf_interface
370+
; cf_is_objc_block } [@warning "+9"] ) =
371+
()

test/passing/tests/extensions-indent.ml.ref

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,6 @@ let _ =
423423
| (module%ext M : S) -> k
424424
| [%ext (module M : S)] -> k
425425
| (exception%ext e) -> k
426-
| ((exception%ext e)[@attr]) -> k
426+
| ((exception%ext e) [@attr]) -> k
427427
| [%ext? exception e] -> k
428428
| _ -> default

test/passing/tests/extensions.ml.ref

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,6 @@ let _ =
423423
| (module%ext M : S) -> k
424424
| [%ext (module M : S)] -> k
425425
| (exception%ext e) -> k
426-
| ((exception%ext e)[@attr]) -> k
426+
| ((exception%ext e) [@attr]) -> k
427427
| [%ext? exception e] -> k
428428
| _ -> default

test/passing/tests/js_source.ml.ocp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[@@@foo]
22

3-
let ((x[@foo]) : (unit[@foo])) = (() [@foo]) [@@foo]
3+
let ((x [@foo]) : (unit[@foo])) = (() [@foo]) [@@foo]
44

55
type t = Foo of (t[@foo]) [@foo] [@@foo]
66

@@ -112,8 +112,8 @@ let () =
112112
[%foo
113113
match[@foo] () with
114114
| [%foo? (* Pattern expressions *)
115-
((lazy x)[@foo])] -> ()
116-
| [%foo? ((exception x)[@foo])] -> ()]
115+
((lazy x) [@foo])] -> ()
116+
| [%foo? ((exception x) [@foo])] -> ()]
117117
;;
118118

119119
(* Class expressions *)
@@ -862,7 +862,7 @@ end
862862

863863
let f = function
864864
| Some (module M : S3) when M.x -> 1
865-
| ((Some _)[@foooo]) -> 2
865+
| ((Some _) [@foooo]) -> 2
866866
| None -> 3
867867
;;
868868

@@ -9376,7 +9376,7 @@ class c =
93769376
end
93779377

93789378
let f = function
9379-
| (x[@wee]) -> ()
9379+
| (x [@wee]) -> ()
93809380
;;
93819381

93829382
let f = function
@@ -9387,13 +9387,13 @@ let f = function
93879387
let f = function
93889388
| [| x1; x2 |] -> ()
93899389
| [||] -> ()
9390-
| ([| x |][@foo]) -> ()
9390+
| ([| x |] [@foo]) -> ()
93919391
| _ -> ()
93929392
;;
93939393

93949394
let g = function
93959395
| { l = x } -> ()
9396-
| ({ l1 = x; l2 = y }[@foo]) -> ()
9396+
| ({ l1 = x; l2 = y } [@foo]) -> ()
93979397
| { l1 = x; l2 = y; _ } -> ()
93989398
;;
93999399

@@ -9496,28 +9496,28 @@ let g x y = ~$(x.contents) y.contents
94969496
let tail1 = ([ 1; 2 ] [@hello])
94979497
let tail2 = 0 :: ([ 1; 2 ] [@hello])
94989498
let tail3 = 0 :: ([] [@hello])
9499-
let f ~l:(l[@foo]) = l
9499+
let f ~l:(l [@foo]) = l
95009500
let test x y = (( + ) [@foo]) x y
95019501
let test x = (( ~- ) [@foo])x
95029502
let test contents = { contents = contents [@foo] }
95039503

95049504
class type t = object (_[@foo]) end
95059505

9506-
class t = object (_[@foo]) end
9506+
class t = object (_ [@foo]) end
95079507

95089508
let test f x = f ~x:(x [@foo])
95099509

95109510
let f = function
9511-
| (`A | `B)[@bar] | `C -> ()
9511+
| (`A | `B) [@bar] | `C -> ()
95129512
;;
95139513

95149514
let f = function
9515-
| _ :: ((_ :: _)[@foo]) -> ()
9515+
| _ :: ((_ :: _) [@foo]) -> ()
95169516
| _ -> ()
95179517
;;
95189518

95199519
function
9520-
| { contents = (contents[@foo]) } -> ()
9520+
| { contents = (contents [@foo]) } -> ()
95219521
;;
95229522

95239523
fun contents -> { contents = contents [@foo] };;

test/passing/tests/js_source.ml.ref

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[@@@foo]
22

3-
let ((x[@foo]) : (unit[@foo])) = (() [@foo]) [@@foo]
3+
let ((x [@foo]) : (unit[@foo])) = (() [@foo]) [@@foo]
44

55
type t = Foo of (t[@foo]) [@foo] [@@foo]
66

@@ -112,8 +112,8 @@ let () =
112112
[%foo
113113
match[@foo] () with
114114
| [%foo? (* Pattern expressions *)
115-
((lazy x)[@foo])] -> ()
116-
| [%foo? ((exception x)[@foo])] -> ()]
115+
((lazy x) [@foo])] -> ()
116+
| [%foo? ((exception x) [@foo])] -> ()]
117117
;;
118118

119119
(* Class expressions *)
@@ -862,7 +862,7 @@ end
862862

863863
let f = function
864864
| Some (module M : S3) when M.x -> 1
865-
| ((Some _)[@foooo]) -> 2
865+
| ((Some _) [@foooo]) -> 2
866866
| None -> 3
867867
;;
868868

@@ -9376,7 +9376,7 @@ class c =
93769376
end
93779377

93789378
let f = function
9379-
| (x[@wee]) -> ()
9379+
| (x [@wee]) -> ()
93809380
;;
93819381

93829382
let f = function
@@ -9387,13 +9387,13 @@ let f = function
93879387
let f = function
93889388
| [| x1; x2 |] -> ()
93899389
| [||] -> ()
9390-
| ([| x |][@foo]) -> ()
9390+
| ([| x |] [@foo]) -> ()
93919391
| _ -> ()
93929392
;;
93939393

93949394
let g = function
93959395
| { l = x } -> ()
9396-
| ({ l1 = x; l2 = y }[@foo]) -> ()
9396+
| ({ l1 = x; l2 = y } [@foo]) -> ()
93979397
| { l1 = x; l2 = y; _ } -> ()
93989398
;;
93999399

@@ -9496,28 +9496,28 @@ let g x y = ~$(x.contents) y.contents
94969496
let tail1 = ([ 1; 2 ] [@hello])
94979497
let tail2 = 0 :: ([ 1; 2 ] [@hello])
94989498
let tail3 = 0 :: ([] [@hello])
9499-
let f ~l:(l[@foo]) = l
9499+
let f ~l:(l [@foo]) = l
95009500
let test x y = (( + ) [@foo]) x y
95019501
let test x = (( ~- ) [@foo])x
95029502
let test contents = { contents = contents [@foo] }
95039503

95049504
class type t = object (_[@foo]) end
95059505

9506-
class t = object (_[@foo]) end
9506+
class t = object (_ [@foo]) end
95079507

95089508
let test f x = f ~x:(x [@foo])
95099509

95109510
let f = function
9511-
| (`A | `B)[@bar] | `C -> ()
9511+
| (`A | `B) [@bar] | `C -> ()
95129512
;;
95139513

95149514
let f = function
9515-
| _ :: ((_ :: _)[@foo]) -> ()
9515+
| _ :: ((_ :: _) [@foo]) -> ()
95169516
| _ -> ()
95179517
;;
95189518

95199519
function
9520-
| { contents = (contents[@foo]) } -> ()
9520+
| { contents = (contents [@foo]) } -> ()
95219521
;;
95229522

95239523
fun contents -> { contents = contents [@foo] };;

test/passing/tests/label_option_default_args.ml.ref

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,14 @@ let f ?open_:(Int.(zero)) = ()
162162
let f ?unpack:((module P)) = ()
163163

164164
(* May need extra parens to handle attributes *)
165-
let f ?any:(_[@attr]) = ()
165+
let f ?any:(_ [@attr]) = ()
166166

167-
let f ?constant:(0[@attr]) = ()
167+
let f ?constant:(0 [@attr]) = ()
168168

169-
let f ?open_:(Int.(zero)[@attr]) = ()
169+
let f ?open_:(Int.(zero) [@attr]) = ()
170170

171-
let f ?or_:((Some () | None)[@attr]) = ()
171+
let f ?or_:((Some () | None) [@attr]) = ()
172172

173-
let f ?unpack:((module P)[@attr]) = ()
173+
let f ?unpack:((module P) [@attr]) = ()
174174

175-
let f ?tuple:((1, 2)[@attr]) = ()
175+
let f ?tuple:((1, 2) [@attr]) = ()

test/passing/tests/object.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,11 @@ let o =
222222
Int_bin_comparison (self#expression a, op, self#expression b)
223223
end
224224

225-
class f = fun [@inline] (b[@inline]) -> object end
225+
class f = fun [@inline] (b [@inline]) -> object end
226226

227227
class f = [%test] [@test]
228228

229-
class f a (b[@inline]) = object end
229+
class f a (b [@inline]) = object end
230230

231231
class f =
232232
object (self)

test/passing/tests/shortcut_ext_attr.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ let () =
3030
[%foo
3131
match[@foo] () with
3232
| [%foo? (* Pattern expressions *)
33-
((lazy x)[@foo])] -> ()
34-
| [%foo? ((exception x)[@foo])] -> ()]
33+
((lazy x) [@foo])] -> ()
34+
| [%foo? ((exception x) [@foo])] -> ()]
3535

3636
(* Class expressions *)
3737
class x =

0 commit comments

Comments
 (0)