@@ -3870,7 +3870,7 @@ and fmt_functor_param_type c ctx = function
38703870 | Pfunctorty_unnamed arg ->
38713871 compose_module (fmt_module_type c (sub_mty ~ctx arg)) ~f: Fn. id
38723872
3873- and fmt_module_type c ?(rec_ = false ) ({ast = mty ; _ } as xmty ) =
3873+ and fmt_module_type c ?(rec_ = false ) ({ast = mty ; ctx = ctx0 } as xmty ) =
38743874 let ctx = Mty mty in
38753875 let {pmty_desc; pmty_loc; pmty_attributes} = mty in
38763876 update_config_maybe_disabled_block c pmty_loc pmty_attributes
@@ -3916,8 +3916,19 @@ and fmt_module_type c ?(rec_ = false) ({ast= mty; _} as xmty) =
39163916 $ fmt_attributes_and_docstrings c pmty_attributes ) }
39173917 | Pmty_functor (paramty , mt ) ->
39183918 let blk = fmt_module_type c (sub_mty ~ctx mt) in
3919+ let opn, cls =
3920+ match ctx0 with
3921+ (* Functor argument might not be boxed. Force a box when using the
3922+ short syntax. *)
3923+ | Mty {pmty_desc= Pmty_functor (Pfunctorty_unnamed lhs, _); _}
3924+ when phys_equal lhs mty ->
3925+ (Some (open_hovbox 2 ), close_box)
3926+ | _ -> (blk.opn, blk.cls)
3927+ in
39193928 { blk with
3920- pro=
3929+ opn
3930+ ; cls
3931+ ; pro=
39213932 Some
39223933 ( Cmts. fmt_before c pmty_loc
39233934 $ fmt_if parens (str " (" )
@@ -4162,10 +4173,23 @@ and fmt_module c ctx ?rec_ ?epi ?(can_sparse = false) keyword ?(eqty = "=")
41624173 let ext = attrs.attrs_extension in
41634174 let blk_t =
41644175 Option. value_map xmty ~default: empty ~f: (fun xmty ->
4176+ let break_before_ty =
4177+ match xmty.ast.pmty_desc with
4178+ (* Break functor types that use the short syntax and avoid
4179+ misaligning the parameter types. *)
4180+ | Pmty_functor
4181+ ( Pfunctorty_unnamed
4182+ {pmty_desc= Pmty_with _ | Pmty_functor _; _}
4183+ , _ ) ->
4184+ break 1 2
4185+ | _ -> str " "
4186+ in
41654187 let blk = fmt_module_type ?rec_ c xmty in
4188+ let pro =
4189+ str " " $ str eqty $ opt blk.pro (fun pro -> break_before_ty $ pro)
4190+ in
41664191 { blk with
4167- pro=
4168- Some (str " " $ str eqty $ opt blk.pro (fun pro -> str " " $ pro))
4192+ pro= Some pro
41694193 ; psp= fmt_if (Option. is_none blk.pro) (break 1 2 ) $ blk.psp } )
41704194 in
41714195 let blk_b = Option. value_map xbody ~default: empty ~f: (fmt_module_expr c) in
0 commit comments