@@ -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 " (" )
@@ -4166,7 +4177,11 @@ and fmt_module c ctx ?rec_ ?epi ?(can_sparse = false) keyword ?(eqty = "=")
41664177 match xmty.ast.pmty_desc with
41674178 (* Break functor types that use the short syntax and avoid
41684179 misaligning the parameter types. *)
4169- | Pmty_functor (Pfunctorty_unnamed _ , _ ) -> break 1 2
4180+ | Pmty_functor
4181+ ( Pfunctorty_unnamed
4182+ {pmty_desc= Pmty_with _ | Pmty_functor _; _}
4183+ , _ ) ->
4184+ break 1 2
41704185 | _ -> str " "
41714186 in
41724187 let blk = fmt_module_type ?rec_ c xmty in
0 commit comments