From 7f03d9e3d3d4ad5c7b24437073d5ada206e56e6c Mon Sep 17 00:00:00 2001 From: Cheng Lou Date: Sat, 24 Feb 2018 06:06:13 -0800 Subject: [PATCH 1/2] [Super errors] Tweak missing argument msg Fixes #https://github.com/reasonml-community/error-message-improvement/issues/45 --- jscomp/super_errors/super_typecore.ml | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/jscomp/super_errors/super_typecore.ml b/jscomp/super_errors/super_typecore.ml index 6b0c0f8fea..52ec94e1e7 100644 --- a/jscomp/super_errors/super_typecore.ml +++ b/jscomp/super_errors/super_typecore.ml @@ -67,6 +67,16 @@ let rec collect_missing_arguments rettype targettype = match rettype with end | _ -> None +let rec collect_missing_arguments_right_to_left rettype targettype = match rettype with +(* TODO *) + | {desc=Tarrow (label, argtype, rettype, _)} when rettype.desc = targettype.desc -> Some ((label, argtype) :: []) + | {desc=Tarrow (label, argtype, rettype, _)} -> begin + match collect_missing_arguments rettype targettype with + | Some res -> Some ((label, argtype) :: res) + | None -> None + end + | _ -> None + let check_bs_arity_mismatch ppf trace = let arity t = match t.desc with | Tvariant { row_fields = [(label,_)] } -> @@ -153,12 +163,21 @@ let report_error env ppf = function | Some (actual, expected) -> collect_missing_arguments actual expected | None -> assert false in + let print_arguments = + Format.pp_print_list + ~pp_sep:(fun ppf _ -> fprintf ppf ",@ ") + (fun ppf (label, argtype) -> + if label = "" then fprintf ppf "@[%a@]" type_expr argtype + else fprintf ppf "@[(~%s: %a)@]" label type_expr argtype + ) + in match missing_arguments with + | Some [singleArgument] -> + fprintf ppf "@[@{This call is missing a final argument@} of type@ %a@]" + print_arguments [singleArgument] | Some arguments -> - fprintf ppf "You're missing arguments: @[%a@]" (Format.pp_print_list ~pp_sep:(fun ppf _ -> fprintf ppf ", ") (fun ppf (label, argtype) -> - if label = "" then type_expr ppf argtype - else fprintf ppf "~%s: %a" label type_expr argtype - )) arguments + fprintf ppf "@[@{This call is missing final arguments@} of type:@ %a@]" + print_arguments arguments | None -> check_bs_arity_mismatch ppf trace; super_report_unification_error ppf env trace From 94a28228b5924f30a9af418445b19674adbe05d7 Mon Sep 17 00:00:00 2001 From: Cheng Lou Date: Mon, 26 Feb 2018 15:25:40 -0800 Subject: [PATCH 2/2] Remove unused code --- jscomp/super_errors/super_typecore.ml | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/jscomp/super_errors/super_typecore.ml b/jscomp/super_errors/super_typecore.ml index 52ec94e1e7..73151413e2 100644 --- a/jscomp/super_errors/super_typecore.ml +++ b/jscomp/super_errors/super_typecore.ml @@ -67,16 +67,6 @@ let rec collect_missing_arguments rettype targettype = match rettype with end | _ -> None -let rec collect_missing_arguments_right_to_left rettype targettype = match rettype with -(* TODO *) - | {desc=Tarrow (label, argtype, rettype, _)} when rettype.desc = targettype.desc -> Some ((label, argtype) :: []) - | {desc=Tarrow (label, argtype, rettype, _)} -> begin - match collect_missing_arguments rettype targettype with - | Some res -> Some ((label, argtype) :: res) - | None -> None - end - | _ -> None - let check_bs_arity_mismatch ppf trace = let arity t = match t.desc with | Tvariant { row_fields = [(label,_)] } ->