Skip to content

Commit

Permalink
Improve error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
lukemaurer committed Oct 25, 2024
1 parent bd1f2d3 commit 39d68c0
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -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".
4 changes: 2 additions & 2 deletions testsuite/tests/templates/basic/bad_ref_direct.reference
Original file line number Diff line number Diff line change
@@ -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".
Original file line number Diff line number Diff line change
@@ -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".
25 changes: 15 additions & 10 deletions typing/persistent_env.ml
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,7 @@ let report_error ppf =
| Illegal_import_of_parameter(modname, filename) ->
fprintf ppf
"@[<hov>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.@]@.\
@[<hov>@{<hint>Hint@}: \
@[<hov>Compile the current unit with \
@{<inline_code>-parameter %a@}.@]@]"
Expand Down Expand Up @@ -1021,7 +1021,7 @@ let report_error ppf =
match valid_parameters with
| [] ->
fprintf ppf
"Compile %a@ with @{<inline_code>-parameter %a@} to make it a \
"Compile %a@ with @{<inline_code>-parameter %a@}@ to make it a \
parameter."
(Style.as_inline_code CU.Name.print) modname
Global_module.Name.print param
Expand All @@ -1030,34 +1030,39 @@ 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:@ @[<hov>%a@]"
fprintf ppf "Parameters for %a:@ @[<hov>%a@]"
(Style.as_inline_code CU.Name.print) modname
print_params valid_parameters
in
fprintf ppf
"@[<hov>%a@ is not a valid parameter for the module %a.@]@.\
@[<hov>@{<hint>Hint@}: %a@]"
(Style.as_inline_code Global_module.Name.print) param
"@[<hov>The module %a@ has no parameter %a.@]@.\
@[<hov>@{<hint>Hint@}: @[<hov>%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
"@[<hov>The module %a@ cannot be used as an argument for parameter \
%a.@]@.\
@[<hov>@{<hint>Hint@}: Compile %a with \
@{<inline_code>-as-argument-for %a@}.@]"
@[<hov>@{<hint>Hint@}: \
@[<hov>Compile %a@ with @{<inline_code>-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
Global_module.Name.print param
| Argument_type_mismatch { value; filename; expected; actual; } ->
fprintf ppf
"@[<hov>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.@]@.\
@[<hov>@{<hint>Hint@}: \
@[<hov>%a@ was compiled with \
@{<inline_code>-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
Expand Down

0 comments on commit 39d68c0

Please sign in to comment.