Skip to content

Commit f91e2ab

Browse files
art-wpanglesd
authored andcommitted
Fix missing parens for polymorphic arguments
1 parent 4201c48 commit f91e2ab

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

src/document/generator.ml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ module Make (Syntax : SYNTAX) = struct
446446
++ O.sp ++ type_expr dst
447447
(* ++ O.end_hv *)
448448
in
449-
if not needs_parentheses then res else enclose ~l:"(" res ~r:")"
449+
enclose_parens_if_needed res
450450
| Arrow (Some (RawOptional _ as lbl), _src, dst) ->
451451
let res =
452452
O.span
@@ -456,7 +456,7 @@ module Make (Syntax : SYNTAX) = struct
456456
++ O.txt " " ++ Syntax.Type.arrow)
457457
++ O.sp ++ type_expr dst
458458
in
459-
if not needs_parentheses then res else enclose ~l:"(" res ~r:")"
459+
enclose_parens_if_needed res
460460
| Arrow (Some lbl, src, dst) ->
461461
let res =
462462
O.span
@@ -466,7 +466,7 @@ module Make (Syntax : SYNTAX) = struct
466466
++ O.txt " " ++ Syntax.Type.arrow)
467467
++ O.sp ++ type_expr dst
468468
in
469-
if not needs_parentheses then res else enclose ~l:"(" res ~r:")"
469+
enclose_parens_if_needed res
470470
| Tuple lst -> tuple ~needs_parentheses ~boxed:true lst
471471
| Unboxed_tuple lst -> tuple ~needs_parentheses ~boxed:false lst
472472
| Constr (path, args) ->
@@ -478,7 +478,9 @@ module Make (Syntax : SYNTAX) = struct
478478
format_type_path ~delim:`brackets args
479479
(Link.from_path (path :> Paths.Path.t))
480480
| Poly (polyvars, t) ->
481-
O.txt ("'" ^ String.concat ~sep:" '" polyvars ^ ". ") ++ type_expr t
481+
enclose_parens_if_needed
482+
@@ O.txt ("'" ^ String.concat ~sep:" '" polyvars ^ ". ")
483+
++ type_expr t
482484
| Quote t -> O.span (O.txt "<[ " ++ O.box_hv (type_expr t) ++ O.txt " ]>")
483485
| Splice t -> O.span (O.txt "$" ++ type_expr ~needs_parentheses:true t)
484486
| Package pkg ->

test/generators/cases/ocaml_55.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ val g : (module M : Y) -> int M.t
1717
val g' : (module M : Y) -> int
1818

1919
val g'' : (module Y) -> int
20+
21+
val map2: ('a. 'a -> 'a) -> 'a * 'b -> 'a * 'b

test/generators/html/Ocaml_55.html

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,28 @@ <h1>Module <code><span>Ocaml_55</span></code></h1>
148148
</code>
149149
</div>
150150
</div>
151+
<div class="odoc-spec">
152+
<div class="spec value anchored" id="val-map2">
153+
<a href="#val-map2" class="anchor"></a>
154+
<code>
155+
<span><span class="keyword">val</span> map2 :
156+
<span>
157+
<span>('a.
158+
<span><span class="type-var">'a</span>
159+
<span class="arrow">&#45;&gt;</span>
160+
</span> <span class="type-var">'a</span>)
161+
</span> <span class="arrow">&#45;&gt;</span>
162+
</span>
163+
<span>
164+
<span>(<span class="type-var">'a</span> *
165+
<span class="type-var">'b</span>)
166+
</span> <span class="arrow">&#45;&gt;</span>
167+
</span> <span class="type-var">'a</span> *
168+
<span class="type-var">'b</span>
169+
</span>
170+
</code>
171+
</div>
172+
</div>
151173
</div>
152174
</body>
153175
</html>

0 commit comments

Comments
 (0)