From 39d68c05ab2a3da0c4a9a2a34ada1acd9265b56f Mon Sep 17 00:00:00 2001 From: Luke Maurer Date: Fri, 25 Oct 2024 17:08:56 +0100 Subject: [PATCH] Improve error messages --- .../bad_instance_arg_name_not_found.reference | 4 +-- ...ad_instance_arg_value_wrong_type.reference | 5 ++-- .../templates/basic/bad_ref_direct.reference | 4 +-- .../basic/bad_ref_direct_imported.reference | 4 +-- typing/persistent_env.ml | 25 +++++++++++-------- 5 files changed, 24 insertions(+), 18 deletions(-) diff --git a/testsuite/tests/templates/basic/bad_instance_arg_name_not_found.reference b/testsuite/tests/templates/basic/bad_instance_arg_name_not_found.reference index 59c61c0fef7..f508cfb5ba9 100644 --- a/testsuite/tests/templates/basic/bad_instance_arg_name_not_found.reference +++ b/testsuite/tests/templates/basic/bad_instance_arg_name_not_found.reference @@ -1,5 +1,5 @@ File "bad_instance_arg_name_not_found.ml", line 2, characters 2-35: 2 | Monoid_utils(Banana)(List_monoid) [@jane.non_erasable.instances] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -Error: "Banana" is not a valid parameter for the module "Monoid_utils". -Hint: Valid parameters for "Monoid_utils": "Monoid" +Error: The module "Monoid_utils" has no parameter "Banana". +Hint: Parameters for "Monoid_utils": "Monoid" diff --git a/testsuite/tests/templates/basic/bad_instance_arg_value_wrong_type.reference b/testsuite/tests/templates/basic/bad_instance_arg_value_wrong_type.reference index 1d1e00fc908..ebdff014301 100644 --- a/testsuite/tests/templates/basic/bad_instance_arg_value_wrong_type.reference +++ b/testsuite/tests/templates/basic/bad_instance_arg_value_wrong_type.reference @@ -2,5 +2,6 @@ File "bad_instance_arg_value_wrong_type.ml", line 2, characters 2-39: 2 | Category_utils(Category)(List_monoid) [@jane.non_erasable.instances] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Error: The module "List_monoid" - is used as an argument for the parameter "Category" but "list_monoid.cmi" - was compiled as an argument for "Monoid". + is used as an argument for the parameter "Category" but "List_monoid" + is an argument for "Monoid". +Hint: "list_monoid.cmi" was compiled with "-as-argument-for Category". diff --git a/testsuite/tests/templates/basic/bad_ref_direct.reference b/testsuite/tests/templates/basic/bad_ref_direct.reference index 67c08ad8510..5790f587d91 100644 --- a/testsuite/tests/templates/basic/bad_ref_direct.reference +++ b/testsuite/tests/templates/basic/bad_ref_direct.reference @@ -1,6 +1,6 @@ File "bad_ref_direct.ml", line 3, characters 12-21: 3 | let empty = Monoid.id ^^^^^^^^^ -Error: The file "monoid.cmi" contains the interface of a parameter. - "Monoid" is not declared as a parameter for the current unit. +Error: The file "monoid.cmi" contains the interface of a parameter. "Monoid" + is not declared as a parameter for the current unit. Hint: Compile the current unit with "-parameter Monoid". diff --git a/testsuite/tests/templates/basic/bad_ref_direct_imported.reference b/testsuite/tests/templates/basic/bad_ref_direct_imported.reference index 7055f6f9c46..e10f16945fc 100644 --- a/testsuite/tests/templates/basic/bad_ref_direct_imported.reference +++ b/testsuite/tests/templates/basic/bad_ref_direct_imported.reference @@ -1,6 +1,6 @@ File "bad_ref_direct_imported.ml", line 7, characters 12-24: 7 | let empty = Monoid.empty ^^^^^^^^^^^^ -Error: The file "monoid.cmi" contains the interface of a parameter. - "Monoid" is not declared as a parameter for the current unit. +Error: The file "monoid.cmi" contains the interface of a parameter. "Monoid" + is not declared as a parameter for the current unit. Hint: Compile the current unit with "-parameter Monoid". diff --git a/typing/persistent_env.ml b/typing/persistent_env.ml index ba4366b5c94..6b0da3153ab 100644 --- a/typing/persistent_env.ml +++ b/typing/persistent_env.ml @@ -987,7 +987,7 @@ let report_error ppf = | Illegal_import_of_parameter(modname, filename) -> fprintf ppf "@[The file %a@ contains the interface of a parameter.@ \ - %a is not declared as a parameter for the current unit.@]@.\ + %a@ is not declared as a parameter for the current unit.@]@.\ @[@{Hint@}: \ @[Compile the current unit with \ @{-parameter %a@}.@]@]" @@ -1021,7 +1021,7 @@ let report_error ppf = match valid_parameters with | [] -> fprintf ppf - "Compile %a@ with @{-parameter %a@} to make it a \ + "Compile %a@ with @{-parameter %a@}@ to make it a \ parameter." (Style.as_inline_code CU.Name.print) modname Global_module.Name.print param @@ -1030,22 +1030,22 @@ let report_error ppf = Format.pp_print_list ~pp_sep:Format.pp_print_space (Style.as_inline_code Global_module.Name.print) in - fprintf ppf "Valid parameters for %a:@ @[%a@]" + fprintf ppf "Parameters for %a:@ @[%a@]" (Style.as_inline_code CU.Name.print) modname print_params valid_parameters in fprintf ppf - "@[%a@ is not a valid parameter for the module %a.@]@.\ - @[@{Hint@}: %a@]" - (Style.as_inline_code Global_module.Name.print) param + "@[The module %a@ has no parameter %a.@]@.\ + @[@{Hint@}: @[%a@]@]" (Style.as_inline_code CU.Name.print) modname + (Style.as_inline_code Global_module.Name.print) param pp_hint () | Not_compiled_as_argument { param; value; filename } -> fprintf ppf "@[The module %a@ cannot be used as an argument for parameter \ %a.@]@.\ - @[@{Hint@}: Compile %a with \ - @{-as-argument-for %a@}.@]" + @[@{Hint@}: \ + @[Compile %a@ with @{-as-argument-for %a@}.@]@]" (Style.as_inline_code Global_module.Name.print) value (Style.as_inline_code Global_module.Name.print) param (Style.as_inline_code Location.print_filename) filename @@ -1053,11 +1053,16 @@ let report_error ppf = | Argument_type_mismatch { value; filename; expected; actual; } -> fprintf ppf "@[The module %a@ is used as an argument for the parameter %a@ \ - but %a@ was compiled as an argument for %a.@]" + but %a@ is an argument for %a.@]@.\ + @[@{Hint@}: \ + @[%a@ was compiled with \ + @{-as-argument-for %a@}.@]@]" (Style.as_inline_code Global_module.Name.print) value (Style.as_inline_code Global_module.Name.print) expected - (Style.as_inline_code Location.print_filename) filename + (Style.as_inline_code Global_module.Name.print) value (Style.as_inline_code Global_module.Name.print) actual + (Style.as_inline_code Location.print_filename) filename + Global_module.Name.print expected | Inconsistent_global_name_resolution { name; old_global; new_global; first_mentioned_by; now_mentioned_by } -> fprintf ppf