@@ -105,8 +105,6 @@ let ident_of_name ppf txt =
105105 else " (%s)"
106106 in fprintf ppf format txt
107107
108- let ident_of_name_loc ppf s = ident_of_name ppf s.txt
109-
110108let protect_longident ppf print_longident longprefix txt =
111109 if not (needs_parens txt) then
112110 fprintf ppf " %a.%a" print_longident longprefix ident_of_name txt
@@ -432,11 +430,11 @@ let include_kind f = function
432430 | Structure -> ()
433431
434432(* c ['a,'b] *)
435- let rec class_params_def ctxt f = function
433+ let rec class_params_def f = function
436434 | [] -> ()
437435 | l ->
438436 pp f " [%a] " (* space *)
439- (list ( type_param ctxt) ~sep: " ," ) l
437+ (list type_param ~sep: " ," ) l
440438
441439and type_with_label ctxt f (label , c , mode ) =
442440 match label with
@@ -499,6 +497,8 @@ and name_jkind f (name, jkind) =
499497 ident_of_name name
500498 (jkind_annotation reset_ctxt) jkind
501499
500+ and name_loc_jkind f (str , jkind ) = name_jkind f (str.txt,jkind)
501+
502502and core_type ctxt f x =
503503 let filtered_attrs = filter_curry_attrs x.ptyp_attributes in
504504 if filtered_attrs <> [] then begin
@@ -686,7 +686,7 @@ and pattern1 ctxt (f:Format.formatter) (x:pattern) : unit =
686686 pp f " %a@;%a" longident_loc li (simple_pattern ctxt) x
687687 | Some (vl , x ) ->
688688 pp f " %a@ (type %a)@;%a" longident_loc li
689- (list ~sep: " @ " ident_of_name_loc ) vl
689+ (list ~sep: " @ " name_loc_jkind ) vl
690690 (simple_pattern ctxt) x
691691 | None -> pp f " %a" longident_loc li)
692692 | _ -> simple_pattern ctxt f x
@@ -1290,7 +1290,7 @@ and class_type_declaration_list ctxt f l =
12901290 let { pci_params= ls; pci_name= { txt; _ }; _ } = x in
12911291 pp f " @[<2>%s %a%a%a@ =@ %a@]%a" kwd
12921292 virtual_flag x.pci_virt
1293- ( class_params_def ctxt) ls
1293+ class_params_def ls
12941294 ident_of_name txt
12951295 (class_type ctxt) x.pci_expr
12961296 (item_attributes ctxt) x.pci_attributes
@@ -1465,15 +1465,15 @@ and module_type ctxt f x =
14651465and with_constraint ctxt f = function
14661466 | Pwith_type (li , ({ptype_params = ls ;_} as td )) ->
14671467 pp f " type@ %a %a =@ %a"
1468- ( type_params ctxt) ls
1468+ type_params ls
14691469 longident_loc li (type_declaration ctxt) td
14701470 | Pwith_module (li , li2 ) ->
14711471 pp f " module %a =@ %a" longident_loc li longident_loc li2;
14721472 | Pwith_modtype (li , mty ) ->
14731473 pp f " module type %a =@ %a" longident_loc li (module_type ctxt) mty;
14741474 | Pwith_typesubst (li , ({ptype_params =ls ;_} as td )) ->
14751475 pp f " type@ %a %a :=@ %a"
1476- ( type_params ctxt) ls
1476+ type_params ls
14771477 longident_loc li
14781478 (type_declaration ctxt) td
14791479 | Pwith_modsubst (li , li2 ) ->
@@ -1528,7 +1528,7 @@ and signature_item ctxt f x : unit =
15281528 let class_description kwd f ({pci_params =ls ;pci_name ={txt;_} ;_} as x ) =
15291529 pp f " @[<2>%s %a%a%a@;:@;%a@]%a" kwd
15301530 virtual_flag x.pci_virt
1531- ( class_params_def ctxt) ls
1531+ class_params_def ls
15321532 ident_of_name txt
15331533 (class_type ctxt) x.pci_expr
15341534 (item_attributes ctxt) x.pci_attributes
@@ -1893,7 +1893,7 @@ and structure_item ctxt f x =
18931893 let args, constr, cl = extract_class_args x.pci_expr in
18941894 pp f " @[<2>%s %a%a%a %a%a=@;%a@]%a" kwd
18951895 virtual_flag x.pci_virt
1896- ( class_params_def ctxt) ls
1896+ class_params_def ls
18971897 ident_of_name txt
18981898 (list (label_exp ctxt) ~last: " @ " ) args
18991899 (option class_constraint) constr
@@ -1968,12 +1968,26 @@ and structure_item ctxt f x =
19681968 | Pstr_kind_abbrev (name , jkind ) ->
19691969 kind_abbrev ctxt f name jkind
19701970
1971- and type_param ctxt f (ct , (a ,b )) =
1972- pp f " %s%s%a" (type_variance a) (type_injectivity b) (core_type ctxt) ct
1971+ (* Don't just use [core_type] because we do not want parens around params
1972+ with jkind annotations *)
1973+ and core_type_param f ct = match ct.ptyp_desc with
1974+ | Ptyp_any None -> pp f " _"
1975+ | Ptyp_any (Some jk ) -> pp f " _ : %a" (jkind_annotation reset_ctxt) jk
1976+ | Ptyp_var (s , None) -> tyvar f s
1977+ | Ptyp_var (s , Some jk ) ->
1978+ pp f " %a : %a" tyvar s (jkind_annotation reset_ctxt) jk
1979+ | _ -> Misc. fatal_error " unexpected type in core_type_param"
19731980
1974- and type_params ctxt f = function
1981+ and type_param f (ct , (a ,b )) =
1982+ pp f " %s%s%a" (type_variance a) (type_injectivity b) core_type_param ct
1983+
1984+ and type_params f = function
19751985 | [] -> ()
1976- | l -> pp f " %a " (list (type_param ctxt) ~first: " (" ~last: " )" ~sep: " ,@;" ) l
1986+ (* Normally, one param doesn't get parentheses, but it does when there is
1987+ a jkind annotation. *)
1988+ | [{ ptyp_desc = Ptyp_any (Some _) | Ptyp_var (_ , Some _ ) }, _ as param ] ->
1989+ pp f " (%a) " type_param param
1990+ | l -> pp f " %a " (list type_param ~first: " (" ~last: " )" ~sep: " ,@;" ) l
19771991
19781992and type_def_list ctxt f (rf , exported , l ) =
19791993 let type_decl kwd rf f x =
@@ -1991,7 +2005,7 @@ and type_def_list ctxt f (rf, exported, l) =
19912005 in
19922006 pp f " @[<2>%s %a%a%a%t%s%a@]%a" kwd
19932007 nonrec_flag rf
1994- ( type_params ctxt) x.ptype_params
2008+ type_params x.ptype_params
19952009 ident_of_name x.ptype_name.txt
19962010 layout_annot eq
19972011 (type_declaration ctxt) x
@@ -2074,11 +2088,7 @@ and type_extension ctxt f x =
20742088 pp f " @\n |@;%a" (extension_constructor ctxt) x
20752089 in
20762090 pp f " @[<2>type %a%a += %a@ %a@]%a"
2077- (fun f -> function
2078- | [] -> ()
2079- | l ->
2080- pp f " %a@;" (list (type_param ctxt) ~first: " (" ~last: " )" ~sep: " ," ) l)
2081- x.ptyext_params
2091+ type_params x.ptyext_params
20822092 longident_loc x.ptyext_path
20832093 private_flag x.ptyext_private (* Cf: #7200 *)
20842094 (list ~sep: " " extension_constructor)
0 commit comments