@@ -194,9 +194,7 @@ and process_type_header_diff name type_privacy_diff type_manifest_diff
194194 let type_name_hunk = Icommon (" " ^ name) in
195195 let equal_hunks = process_equal_sign_diff type_manifest_diff type_kind_diff in
196196 let type_privacy_hunks = process_privacy_diff type_privacy_diff in
197- let type_manifest_hunks =
198- process_manifest_diff ~paren: false type_manifest_diff
199- in
197+ let type_manifest_hunks = process_manifest_diff type_manifest_diff in
200198 let type_header_hunks =
201199 if List. length equal_hunks = 2 then
202200 List. concat
@@ -340,16 +338,15 @@ and process_equal_sign_diff type_manifest_diff type_kind_diff =
340338 [ Iconflict { iorig = None ; inew = Some " =" } ]
341339 | _ -> [ Icommon " =" ]
342340
343- and process_manifest_diff ~ paren manifest_diff =
341+ and process_manifest_diff manifest_diff =
344342 match manifest_diff with
345343 | Same None -> []
346344 | Same (Some te ) -> [ Icommon (" " ^ type_expr_to_string te) ]
347345 | Changed (Added te ) ->
348346 [ Iconflict { iorig = None ; inew = Some (" " ^ type_expr_to_string te) } ]
349347 | Changed (Removed te ) ->
350348 [ Iconflict { iorig = Some (" " ^ type_expr_to_string te); inew = None } ]
351- | Changed (Modified te_diff ) ->
352- Icommon " " :: process_type_expr_diff ~paren te_diff
349+ | Changed (Modified te_diff ) -> Icommon " " :: process_type_expr_diff te_diff
353350
354351and process_type_kind_diff kind_diff =
355352 match kind_diff with
@@ -447,35 +444,112 @@ and process_cstr_diff name cstr_diff =
447444 let record_hunks = process_record_type_diff record_diff in
448445 Inline_hunks (Icommon (Printf. sprintf " | %s of " name) :: record_hunks)
449446 | Tuple_cstr tuple_diff ->
450- let tuple_hunks = process_tuple_type_diff tuple_diff in
447+ let tuple_hunks = process_tuple_type_diff ~context: `None tuple_diff in
451448 Inline_hunks (Icommon (Printf. sprintf " | %s of " name) :: tuple_hunks)
452449 )
453450
454- and process_tuple_type_diff diff =
451+ and process_tuple_type_diff ~ context diff =
455452 let module S = Stddiff in
456- List. mapi
457- (fun i te_diff ->
458- let star = if i > 0 then " * " else " " in
459- match te_diff with
460- | S. Same same_te ->
461- [ Icommon (Printf. sprintf " %s%s" star (type_expr_to_string same_te)) ]
462- | Changed (Stddiff. Added te ) ->
463- [
464- Iconflict
465- { iorig = None ; inew = Some (star ^ type_expr_to_string te) };
466- ]
467- | Changed (Removed te ) ->
468- [
469- Iconflict
470- { iorig = Some (star ^ type_expr_to_string te); inew = None };
471- ]
472- | Changed (Modified te ) ->
473- let te_hunks = process_type_expr_diff ~paren: true te in
474- if i > 0 then Icommon " * " :: te_hunks else te_hunks)
475- diff
476- |> List. concat
477-
478- and process_type_expr_diff ?(paren = true ) (diff : Diff.type_expr ) :
453+ let tuple_hunks =
454+ List. mapi
455+ (fun i te_diff ->
456+ let star = if i > 0 then " * " else " " in
457+ match te_diff with
458+ | S. Same same_te ->
459+ [
460+ Icommon (Printf. sprintf " %s%s" star (type_expr_to_string same_te));
461+ ]
462+ | Changed (Stddiff. Added te ) ->
463+ [
464+ Iconflict
465+ { iorig = None ; inew = Some (star ^ type_expr_to_string te) };
466+ ]
467+ | Changed (Removed te ) ->
468+ [
469+ Iconflict
470+ { iorig = Some (star ^ type_expr_to_string te); inew = None };
471+ ]
472+ | Changed (Modified te ) ->
473+ let te_hunks = process_type_expr_diff ~context: `Tuple te in
474+ if i > 0 then Icommon " * " :: te_hunks else te_hunks)
475+ diff
476+ |> List. concat
477+ in
478+ match context with
479+ | `Tuple -> parenthesize tuple_hunks
480+ | `None | `Larrow -> tuple_hunks
481+
482+ and process_arg_label_diff diff =
483+ let module S = Stddiff in
484+ let open Diff in
485+ let arg_label_to_string arg_label =
486+ let open Diff in
487+ match arg_label with
488+ | Labelled_arg name -> name ^ " :"
489+ | Optional_arg name -> " ?" ^ name ^ " :"
490+ in
491+ match diff with
492+ | S. Same None -> []
493+ | Same (Some arg_label ) -> [ Icommon (arg_label_to_string arg_label) ]
494+ | Changed (S. Added arg_label ) ->
495+ [
496+ Iconflict { iorig = None ; inew = Some (arg_label_to_string arg_label) };
497+ ]
498+ | Changed (Removed arg_label ) ->
499+ [
500+ Iconflict { iorig = Some (arg_label_to_string arg_label); inew = None };
501+ ]
502+ | Changed (Modified diff ) ->
503+ let name_ihunk =
504+ match diff.name with
505+ | Same name -> [ Icommon (name ^ " :" ) ]
506+ | Changed { reference; current } ->
507+ [
508+ Iconflict { iorig = Some reference; inew = Some current };
509+ Icommon " :" ;
510+ ]
511+ in
512+ let optional_arg_ihunk =
513+ match diff.arg_optional with
514+ | Same true -> [ Icommon " ?" ]
515+ | Same false -> []
516+ | Changed Added_opt_arg ->
517+ [ Iconflict { iorig = None ; inew = Some " ?" } ]
518+ | Changed Removed_opt_arg ->
519+ [ Iconflict { iorig = Some " ?" ; inew = None } ]
520+ in
521+ optional_arg_ihunk @ name_ihunk
522+
523+ and process_arrow_type_diff ~context arrow_diff =
524+ let open Diff in
525+ let module S = Stddiff in
526+ let arg_label_ihunks = process_arg_label_diff arrow_diff.arg_label in
527+ let arg_type_ihunks =
528+ match arrow_diff.arg_type with
529+ | Same type_expr -> [ Icommon (type_expr_to_string type_expr) ]
530+ | Changed type_expr -> process_type_expr_diff ~context: `Larrow type_expr
531+ in
532+ let return_type_ihunks =
533+ match arrow_diff.return_type with
534+ | Same type_expr -> [ Icommon (type_expr_to_string type_expr) ]
535+ | Changed type_expr -> process_type_expr_diff type_expr
536+ in
537+ let arrow_hunks =
538+ List. concat
539+ [
540+ arg_label_ihunks;
541+ arg_type_ihunks;
542+ [ Icommon " -> " ];
543+ return_type_ihunks;
544+ ]
545+ in
546+ match context with
547+ | `Tuple | `Larrow -> parenthesize arrow_hunks
548+ | `None -> arrow_hunks
549+
550+ and parenthesize hunks = (Icommon " (" :: hunks) @ [ Icommon " )" ]
551+
552+ and process_type_expr_diff ?(context = `None ) (diff : Diff.type_expr ) :
479553 inline_hunk list =
480554 match diff with
481555 | Diff. Atomic { reference; current } ->
@@ -486,10 +560,8 @@ and process_type_expr_diff ?(paren = true) (diff : Diff.type_expr) :
486560 inew = Some (type_expr_to_string current);
487561 };
488562 ]
489- | Tuple tuple_diff ->
490- let tuple_hunks = process_tuple_type_diff tuple_diff in
491- if paren then (Icommon " (" :: tuple_hunks) @ [ Icommon " )" ]
492- else tuple_hunks
563+ | Tuple tuple_diff -> process_tuple_type_diff ~context tuple_diff
564+ | Arrow arrow_diff -> process_arrow_type_diff ~context arrow_diff
493565
494566and cstr_args_to_line cstr_args =
495567 match cstr_args with
0 commit comments