@@ -816,6 +816,7 @@ type if_then_else =
816816 ; box_keyword_and_expr : Fmt .t -> Fmt .t
817817 ; branch_pro : Fmt .t
818818 ; wrap_parens : Fmt .t -> Fmt .t
819+ ; beginend_loc : Location .t option
819820 ; box_expr : bool option
820821 ; expr_pro : Fmt .t option
821822 ; expr_eol : Fmt .t option
@@ -827,17 +828,21 @@ let get_if_then_else (c : Conf.t) ~pro ~first ~last ~parens_bch
827828 ~parens_prev_bch ~xcond ~xbch ~expr_loc ~fmt_infix_ext_attrs
828829 ~infix_ext_attrs ~fmt_cond ~cmts_before_kw ~cmts_after_kw =
829830 let imd = c.fmt_opts.indicate_multiline_delimiters.v in
830- let beginend , infix_ext_attrs_beginend, branch_expr =
831+ let beginend_loc , infix_ext_attrs_beginend, branch_expr =
831832 let ast = xbch.Ast. ast in
832833 match ast with
833834 | { pexp_desc= Pexp_beginend (nested_exp, infix_ext_attrs)
834835 ; pexp_attributes= []
836+ ; pexp_loc
835837 ; _ } ->
836- (true , Some infix_ext_attrs, sub_exp ~ctx: (Exp ast) nested_exp)
837- | _ -> (false , None , xbch)
838+ ( Some pexp_loc
839+ , Some infix_ext_attrs
840+ , sub_exp ~ctx: (Exp ast) nested_exp )
841+ | _ -> (None , None , xbch)
838842 in
843+ let has_beginend = Option. is_some beginend_loc in
839844 let wrap_parens ~wrap_breaks k =
840- if beginend then
845+ if has_beginend then
841846 let infix_ext_attrs_beginend =
842847 Option. value_exn infix_ext_attrs_beginend
843848 in
@@ -848,15 +853,15 @@ let get_if_then_else (c : Conf.t) ~pro ~first ~last ~parens_bch
848853 in
849854 let get_parens_breaks ~opn_hint_indent ~cls_hint :(ch_sp , ch_sl ) =
850855 let brk hint = fits_breaks " " ~hint " " in
851- let oh_other = ((if beginend then 1 else 0 ), opn_hint_indent) in
852- if beginend then
856+ if has_beginend then
853857 let _, offset = ch_sl in
854- wrap (brk oh_other ) (break 1000 offset)
858+ wrap (brk ( 1 , opn_hint_indent) ) (break 1000 offset)
855859 else
856860 match imd with
857861 | `Space -> wrap (brk (1 , opn_hint_indent)) (brk ch_sp)
858- | `No -> wrap (brk oh_other) noop
859- | `Closing_on_separate_line -> wrap (brk oh_other) (brk ch_sl)
862+ | `No -> wrap (brk (0 , opn_hint_indent)) noop
863+ | `Closing_on_separate_line ->
864+ wrap (brk (0 , opn_hint_indent)) (brk ch_sl)
860865 in
861866 let cond () =
862867 match xcond with
@@ -875,7 +880,7 @@ let get_if_then_else (c : Conf.t) ~pro ~first ~last ~parens_bch
875880 in
876881 let branch_pro ?(indent = 2 ) () =
877882 if Option. is_some cmts_after_kw then break 1000 indent
878- else if beginend || parens_bch then str " "
883+ else if has_beginend || parens_bch then str " "
879884 else break 1 indent
880885 in
881886 match c.fmt_opts.if_then_else.v with
@@ -889,6 +894,7 @@ let get_if_then_else (c : Conf.t) ~pro ~first ~last ~parens_bch
889894 ~wrap_breaks:
890895 (get_parens_breaks ~opn_hint_indent: 0
891896 ~cls_hint: ((1 , 0 ), (1000 , - 2 )) )
897+ ; beginend_loc
892898 ; box_expr= Some false
893899 ; expr_pro= None
894900 ; expr_eol= None
@@ -901,13 +907,15 @@ let get_if_then_else (c : Conf.t) ~pro ~first ~last ~parens_bch
901907 ; box_keyword_and_expr= Fn. id
902908 ; branch_pro= branch_pro ()
903909 ; wrap_parens= wrap_parens ~wrap_breaks: (wrap (break 1000 2 ) noop)
904- ; box_expr= Some beginend
910+ ; beginend_loc
911+ ; box_expr= Some has_beginend
905912 ; expr_pro= None
906913 ; expr_eol= Some (break 1 2 )
907914 ; branch_expr
908915 ; break_end_branch=
909- fmt_if (parens_bch || beginend || not last) (break 1000 0 )
910- ; space_between_branches= fmt_if (beginend || parens_bch) (str " " ) }
916+ fmt_if (parens_bch || has_beginend || not last) (break 1000 0 )
917+ ; space_between_branches= fmt_if (has_beginend || parens_bch) (str " " )
918+ }
911919 | `Fit_or_vertical ->
912920 { box_branch=
913921 hovbox
@@ -922,6 +930,7 @@ let get_if_then_else (c : Conf.t) ~pro ~first ~last ~parens_bch
922930 ~wrap_breaks:
923931 (get_parens_breaks ~opn_hint_indent: 2
924932 ~cls_hint: ((1 , 0 ), (1000 , 0 )) )
933+ ; beginend_loc
925934 ; box_expr= Some false
926935 ; expr_pro=
927936 Some
@@ -933,7 +942,8 @@ let get_if_then_else (c : Conf.t) ~pro ~first ~last ~parens_bch
933942 ; break_end_branch= noop
934943 ; space_between_branches=
935944 ( match imd with
936- | `Closing_on_separate_line when beginend || parens_bch -> str " "
945+ | `Closing_on_separate_line when has_beginend || parens_bch ->
946+ str " "
937947 | _ -> space_break ) }
938948 | `Vertical ->
939949 { box_branch= Fn. id
@@ -945,6 +955,7 @@ let get_if_then_else (c : Conf.t) ~pro ~first ~last ~parens_bch
945955 ~wrap_breaks:
946956 (get_parens_breaks ~opn_hint_indent: 2
947957 ~cls_hint: ((1 , 0 ), (1000 , 0 )) )
958+ ; beginend_loc
948959 ; box_expr= None
949960 ; expr_pro= Some (break_unless_newline 1000 2 )
950961 ; expr_eol= None
@@ -979,6 +990,7 @@ let get_if_then_else (c : Conf.t) ~pro ~first ~last ~parens_bch
979990 ~wrap_breaks:
980991 (get_parens_breaks ~opn_hint_indent: 0
981992 ~cls_hint: ((1 , 0 ), (1000 , - 2 )) )
993+ ; beginend_loc
982994 ; box_expr= None
983995 ; expr_pro= None
984996 ; expr_eol= None
0 commit comments