Skip to content

Commit c121f6c

Browse files
Julowjonludlam
authored andcommitted
Add missing parentheses in type expr (_ as 'a) t
1 parent 10ac740 commit c121f6c

File tree

7 files changed

+27
-19
lines changed

7 files changed

+27
-19
lines changed

src/document/generator.ml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,12 +409,16 @@ module Make (Syntax : SYNTAX) = struct
409409

410410
and type_expr ?(needs_parentheses = false) (t : Odoc_model.Lang.TypeExpr.t)
411411
=
412+
let enclose_parens_if_needed res =
413+
if needs_parentheses then enclose ~l:"(" res ~r:")" else res
414+
in
412415
match t with
413416
| Var s -> type_var (Syntax.Type.var_prefix ^ s)
414417
| Any -> type_var Syntax.Type.any
415418
| Alias (te, alias) ->
416-
type_expr ~needs_parentheses:true te
417-
++ O.txt " " ++ O.keyword "as" ++ O.txt " '" ++ O.txt alias
419+
enclose_parens_if_needed
420+
(type_expr ~needs_parentheses:true te
421+
++ O.txt " " ++ O.keyword "as" ++ O.txt " '" ++ O.txt alias)
418422
| Arrow (None, src, dst) ->
419423
let res =
420424
O.span

test/generators/html/Ocamlary.html

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,9 +1412,10 @@ <h4 id="advanced-type-stuff">
14121412
<code>
14131413
<span><span class="keyword">type</span> <span>'a poly_fun</span></span>
14141414
<span> =
1415-
<span><span>[&gt; <span>`ConstrB of int</span> ]</span>
1416-
<span class="keyword">as</span> 'a
1417-
<span class="arrow">&#45;&gt;</span>
1415+
<span>
1416+
<span>(<span>[&gt; <span>`ConstrB of int</span> ]</span>
1417+
<span class="keyword">as</span> 'a)
1418+
</span> <span class="arrow">&#45;&gt;</span>
14181419
</span> <span class="type-var">'a</span>
14191420
</span>
14201421
</code>
@@ -1746,9 +1747,10 @@ <h4 id="advanced-type-stuff">
17461747
<a href="#type-oof" class="anchor"></a>
17471748
<code><span><span class="keyword">type</span> <span>'a oof</span></span>
17481749
<span> =
1749-
<span><span>&lt; a : unit.. &gt;</span>
1750-
<span class="keyword">as</span> 'a
1751-
<span class="arrow">&#45;&gt;</span>
1750+
<span>
1751+
<span>(<span>&lt; a : unit.. &gt;</span>
1752+
<span class="keyword">as</span> 'a)
1753+
</span> <span class="arrow">&#45;&gt;</span>
17521754
</span> <span class="type-var">'a</span>
17531755
</span>
17541756
</code>

test/generators/html/Type.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -734,8 +734,8 @@ <h1>Module <code><span>Type</span></code></h1>
734734
<div class="spec type anchored" id="type-as_">
735735
<a href="#type-as_" class="anchor"></a>
736736
<code><span><span class="keyword">type</span> as_</span>
737-
<span> = int <span class="keyword">as</span> 'a *
738-
<span class="type-var">'a</span>
737+
<span> = <span>(int <span class="keyword">as</span> 'a)</span>
738+
* <span class="type-var">'a</span>
739739
</span>
740740
</code>
741741
</div>
@@ -837,7 +837,9 @@ <h1>Module <code><span>Type</span></code></h1>
837837
<a href="#type-t" class="anchor"></a>
838838
<code><span><span class="keyword">type</span> <span>'a t</span></span>
839839
<span> =
840-
<span><span>[ `A ]</span> <span class="keyword">as</span> 'a option
840+
<span>
841+
<span>(<span>[ `A ]</span> <span class="keyword">as</span> 'a)</span>
842+
option
841843
</span>
842844
</span>
843845
</code>

test/generators/latex/Ocamlary.tex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ \subsubsection{Advanced Type Stuff\label{advanced-type-stuff}}%
497497
\label{Ocamlary-type-open_poly_variant}\ocamlcodefragment{\ocamltag{keyword}{type} 'a open\_\allowbreak{}poly\_\allowbreak{}variant = [> `TagA ] \ocamltag{keyword}{as} 'a}\\
498498
\label{Ocamlary-type-open_poly_variant2}\ocamlcodefragment{\ocamltag{keyword}{type} 'a open\_\allowbreak{}poly\_\allowbreak{}variant2 = [> `ConstrB of int ] \ocamltag{keyword}{as} 'a}\\
499499
\label{Ocamlary-type-open_poly_variant_alias}\ocamlcodefragment{\ocamltag{keyword}{type} 'a open\_\allowbreak{}poly\_\allowbreak{}variant\_\allowbreak{}alias = \ocamltag{type-var}{'a} \hyperref[Ocamlary-type-open_poly_variant]{\ocamlinlinecode{open\_\allowbreak{}poly\_\allowbreak{}variant}} \hyperref[Ocamlary-type-open_poly_variant2]{\ocamlinlinecode{open\_\allowbreak{}poly\_\allowbreak{}variant2}}}\\
500-
\label{Ocamlary-type-poly_fun}\ocamlcodefragment{\ocamltag{keyword}{type} 'a poly\_\allowbreak{}fun = [> `ConstrB of int ] \ocamltag{keyword}{as} 'a \ocamltag{arrow}{$\rightarrow$} \ocamltag{type-var}{'a}}\\
500+
\label{Ocamlary-type-poly_fun}\ocamlcodefragment{\ocamltag{keyword}{type} 'a poly\_\allowbreak{}fun = ([> `ConstrB of int ] \ocamltag{keyword}{as} 'a) \ocamltag{arrow}{$\rightarrow$} \ocamltag{type-var}{'a}}\\
501501
\label{Ocamlary-type-poly_fun_constraint}\ocamlcodefragment{\ocamltag{keyword}{type} 'a poly\_\allowbreak{}fun\_\allowbreak{}constraint = \ocamltag{type-var}{'a} \ocamltag{arrow}{$\rightarrow$} \ocamltag{type-var}{'a} \ocamltag{keyword}{constraint} \ocamltag{type-var}{'a} = [> `TagA ]}\\
502502
\label{Ocamlary-type-closed_poly_variant}\ocamlcodefragment{\ocamltag{keyword}{type} 'a closed\_\allowbreak{}poly\_\allowbreak{}variant = [< `One | `Two ] \ocamltag{keyword}{as} 'a}\\
503503
\label{Ocamlary-type-clopen_poly_variant}\ocamlcodefragment{\ocamltag{keyword}{type} 'a clopen\_\allowbreak{}poly\_\allowbreak{}variant = [< `One | `Two of int | `Three Two Three ] \ocamltag{keyword}{as} 'a}\\
@@ -544,7 +544,7 @@ \subsubsection{Advanced Type Stuff\label{advanced-type-stuff}}%
544544
\medbreak
545545
\label{Ocamlary-type-rec_obj}\ocamlcodefragment{\ocamltag{keyword}{type} rec\_\allowbreak{}obj = < f : int ;\allowbreak{} g : unit \ocamltag{arrow}{$\rightarrow$} unit ;\allowbreak{} h : \hyperref[Ocamlary-type-rec_obj]{\ocamlinlinecode{rec\_\allowbreak{}obj}} >}\\
546546
\label{Ocamlary-type-open_obj}\ocamlcodefragment{\ocamltag{keyword}{type} 'a open\_\allowbreak{}obj = < f : int ;\allowbreak{} g : unit \ocamltag{arrow}{$\rightarrow$} unit.\allowbreak{}.\allowbreak{} > \ocamltag{keyword}{as} 'a}\\
547-
\label{Ocamlary-type-oof}\ocamlcodefragment{\ocamltag{keyword}{type} 'a oof = < a : unit.\allowbreak{}.\allowbreak{} > \ocamltag{keyword}{as} 'a \ocamltag{arrow}{$\rightarrow$} \ocamltag{type-var}{'a}}\\
547+
\label{Ocamlary-type-oof}\ocamlcodefragment{\ocamltag{keyword}{type} 'a oof = (< a : unit.\allowbreak{}.\allowbreak{} > \ocamltag{keyword}{as} 'a) \ocamltag{arrow}{$\rightarrow$} \ocamltag{type-var}{'a}}\\
548548
\label{Ocamlary-type-any_obj}\ocamlcodefragment{\ocamltag{keyword}{type} 'a any\_\allowbreak{}obj = < .\allowbreak{}.\allowbreak{} > \ocamltag{keyword}{as} 'a}\\
549549
\label{Ocamlary-type-empty_obj}\ocamlcodefragment{\ocamltag{keyword}{type} empty\_\allowbreak{}obj = < >}\\
550550
\label{Ocamlary-type-one_meth}\ocamlcodefragment{\ocamltag{keyword}{type} one\_\allowbreak{}meth = < meth : unit >}\\

test/generators/latex/Type.tex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ \section{Module \ocamlinlinecode{Type}}\label{Type}%
114114
\label{Type-type-lower_object}\ocamlcodefragment{\ocamltag{keyword}{type} 'a lower\_\allowbreak{}object = \ocamltag{type-var}{'a} \ocamltag{keyword}{constraint} \ocamltag{type-var}{'a} = < a : int ;\allowbreak{} b : int.\allowbreak{}.\allowbreak{} >}\\
115115
\label{Type-type-poly_object}\ocamlcodefragment{\ocamltag{keyword}{type} 'a poly\_\allowbreak{}object = \ocamltag{type-var}{'a} \ocamltag{keyword}{constraint} \ocamltag{type-var}{'a} = < a : 'a.\allowbreak{} \ocamltag{type-var}{'a} >}\\
116116
\label{Type-type-double_constrained}\ocamlcodefragment{\ocamltag{keyword}{type} ('a,\allowbreak{} 'b) double\_\allowbreak{}constrained = \ocamltag{type-var}{'a} * \ocamltag{type-var}{'b} \ocamltag{keyword}{constraint} \ocamltag{type-var}{'a} = int \ocamltag{keyword}{constraint} \ocamltag{type-var}{'b} = unit}\\
117-
\label{Type-type-as_}\ocamlcodefragment{\ocamltag{keyword}{type} as\_\allowbreak{} = int \ocamltag{keyword}{as} 'a * \ocamltag{type-var}{'a}}\\
117+
\label{Type-type-as_}\ocamlcodefragment{\ocamltag{keyword}{type} as\_\allowbreak{} = (int \ocamltag{keyword}{as} 'a) * \ocamltag{type-var}{'a}}\\
118118
\label{Type-type-extensible}\ocamlcodefragment{\ocamltag{keyword}{type} extensible = .\allowbreak{}.\allowbreak{}}\\
119119
\label{Type-extension-decl-Extension}\ocamlcodefragment{\ocamltag{keyword}{type} \hyperref[Type-type-extensible]{\ocamlinlinecode{extensible}} += }\\
120120
\begin{ocamltabular}{p{0.500\textwidth}p{0.500\textwidth}}\ocamlcodefragment{| \ocamltag{extension}{Extension}}\label{Type-extension-Extension}& Documentation for \hyperref[Type-extension-Extension]{\ocamlinlinecode{\ocamlinlinecode{Extension}}[p\pageref*{Type-extension-Extension}]}.\\
@@ -130,6 +130,6 @@ \section{Module \ocamlinlinecode{Type}}\label{Type}%
130130
\end{ocamltabular}%
131131
\\
132132
\label{Type-exception-Foo}\ocamlcodefragment{\ocamltag{keyword}{exception} \ocamltag{exception}{Foo} \ocamltag{keyword}{of} int * int}\\
133-
\label{Type-type-t}\ocamlcodefragment{\ocamltag{keyword}{type} 'a t = [ `A ] \ocamltag{keyword}{as} 'a option}\\
133+
\label{Type-type-t}\ocamlcodefragment{\ocamltag{keyword}{type} 'a t = ([ `A ] \ocamltag{keyword}{as} 'a) option}\\
134134

135135

test/generators/man/Ocamlary.3o

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,7 +1370,7 @@ This comment is for poly_variant_union\.
13701370
.sp
13711371
\f[CB]type\fR 'a open_poly_variant_alias = \f[CB]'a\fR open_poly_variant open_poly_variant2
13721372
.sp
1373-
\f[CB]type\fR 'a poly_fun = [> `ConstrB of int ] \f[CB]as\fR 'a \f[CB]\->\fR \f[CB]'a\fR
1373+
\f[CB]type\fR 'a poly_fun = ([> `ConstrB of int ] \f[CB]as\fR 'a) \f[CB]\->\fR \f[CB]'a\fR
13741374
.sp
13751375
\f[CB]type\fR 'a poly_fun_constraint = \f[CB]'a\fR \f[CB]\->\fR \f[CB]'a\fR \f[CB]constraint\fR \f[CB]'a\fR = [> `TagA ]
13761376
.sp
@@ -1476,7 +1476,7 @@ This comment is for \f[CI]mutual_constr_b\fR then \f[CI]mutual_constr_a\fR\.
14761476
.sp
14771477
\f[CB]type\fR 'a open_obj = < f : int ; g : unit \f[CB]\->\fR unit\.\. > \f[CB]as\fR 'a
14781478
.sp
1479-
\f[CB]type\fR 'a oof = < a : unit\.\. > \f[CB]as\fR 'a \f[CB]\->\fR \f[CB]'a\fR
1479+
\f[CB]type\fR 'a oof = (< a : unit\.\. > \f[CB]as\fR 'a) \f[CB]\->\fR \f[CB]'a\fR
14801480
.sp
14811481
\f[CB]type\fR 'a any_obj = < \.\. > \f[CB]as\fR 'a
14821482
.sp

test/generators/man/Type.3o

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ e : 'a\. \f[CB]'a\fR;
232232
.sp
233233
\f[CB]type\fR ('a, 'b) double_constrained = \f[CB]'a\fR * \f[CB]'b\fR \f[CB]constraint\fR \f[CB]'a\fR = int \f[CB]constraint\fR \f[CB]'b\fR = unit
234234
.sp
235-
\f[CB]type\fR as_ = int \f[CB]as\fR 'a * \f[CB]'a\fR
235+
\f[CB]type\fR as_ = (int \f[CB]as\fR 'a) * \f[CB]'a\fR
236236
.sp
237237
\f[CB]type\fR extensible = \.\.
238238
.sp
@@ -265,4 +265,4 @@ e : 'a\. \f[CB]'a\fR;
265265
.sp
266266
\f[CB]exception\fR \f[CB]Foo\fR \f[CB]of\fR int * int
267267
.sp
268-
\f[CB]type\fR 'a t = [ `A ] \f[CB]as\fR 'a option
268+
\f[CB]type\fR 'a t = ([ `A ] \f[CB]as\fR 'a) option

0 commit comments

Comments
 (0)