Skip to content

Improve error message around any in functions #2405

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Error: Function arguments and returns must be representable.
The layout of Any_missing_cmi_lib2.t is any, because
the .cmi file for Any_missing_cmi_lib2.t is missing.
But the layout of Any_missing_cmi_lib2.t must be representable, because
it's the type of a function argument.
we must know concretely how to pass a function argument.
No .cmi file found containing Any_missing_cmi_lib2.t.
Hint: Adding "any_missing_cmi_lib2" to your dependencies might help.
|}]
4 changes: 2 additions & 2 deletions ocaml/testsuite/tests/typing-layouts-err-msg/concrete.ml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Error: This pattern matches values of type t_any
The layout of t_any is any, because
of the definition of t_any at line 1, characters 0-16.
But the layout of t_any must be representable, because
it's the type of a function argument.
we must know concretely how to pass a function argument.
|}]

(* Function_result *)
Expand All @@ -120,7 +120,7 @@ Error: This expression has type t_any but an expression was expected of type
The layout of t_any is any, because
of the definition of t_any at line 1, characters 0-16.
But the layout of t_any must be representable, because
it's the type of a function result.
we must know concretely how to return a function result.
|}]

(* Structure_item_expression *)
Expand Down
12 changes: 6 additions & 6 deletions ocaml/testsuite/tests/typing-layouts-missing-cmi/function_arg.ml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Error: Function arguments and returns must be representable.
The layout of Function_a.t is any, because
the .cmi file for Function_a.t is missing.
But the layout of Function_a.t must be representable, because
it's the type of a function argument.
we must know concretely how to pass a function argument.
No .cmi file found containing Function_a.t.
Hint: Adding "function_a" to your dependencies might help.
|}]
Expand All @@ -42,7 +42,7 @@ Error: Function arguments and returns must be representable.
The layout of Function_a.t is any, because
the .cmi file for Function_a.t is missing.
But the layout of Function_a.t must be representable, because
it's the type of a function argument.
we must know concretely how to pass a function argument.
No .cmi file found containing Function_a.t.
Hint: Adding "function_a" to your dependencies might help.
|}]
Expand All @@ -57,7 +57,7 @@ Error: Function arguments and returns must be representable.
The layout of Function_a.t is any, because
the .cmi file for Function_a.t is missing.
But the layout of Function_a.t must be representable, because
it's the type of a function argument.
we must know concretely how to pass a function argument.
No .cmi file found containing Function_a.t.
Hint: Adding "function_a" to your dependencies might help.
|}]
Expand All @@ -72,7 +72,7 @@ Error: Function arguments and returns must be representable.
The layout of Function_a.t is any, because
the .cmi file for Function_a.t is missing.
But the layout of Function_a.t must be representable, because
it's the type of a function result.
we must know concretely how to return a function result.
No .cmi file found containing Function_a.t.
Hint: Adding "function_a" to your dependencies might help.
|}]
Expand All @@ -89,7 +89,7 @@ Error: Function arguments and returns must be representable.
The layout of Function_a.t is any, because
the .cmi file for Function_a.t is missing.
But the layout of Function_a.t must be representable, because
it's the type of a function argument.
we must know concretely how to pass a function argument.
No .cmi file found containing Function_a.t.
Hint: Adding "function_a" to your dependencies might help.
|}]
Expand All @@ -106,7 +106,7 @@ Error: Function arguments and returns must be representable.
The layout of Function_a.t is any, because
the .cmi file for Function_a.t is missing.
But the layout of Function_a.t must be representable, because
it's the type of a function result.
we must know concretely how to return a function result.
No .cmi file found containing Function_a.t.
Hint: Adding "function_a" to your dependencies might help.
|}]
6 changes: 3 additions & 3 deletions ocaml/testsuite/tests/typing-layouts/annots.ml
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ Error: This definition has type 'b -> 'b which is less general than
The layout of 'a is any, because
of the annotation on the universal variable 'a.
But the layout of 'a must be representable, because
it's the type of a function argument.
we must know concretely how to pass a function argument.
|}]
(* CR layouts v2.9: This error message is not great. Check later if layout history
is able to improve it. *)
Expand Down Expand Up @@ -399,7 +399,7 @@ Error: This pattern matches values of type a
The layout of a is any, because
of the annotation on the abstract type declaration for a.
But the layout of a must be representable, because
it's the type of a function argument.
we must know concretely how to pass a function argument.
|}]

(****************************************)
Expand Down Expand Up @@ -433,7 +433,7 @@ Error: Function arguments and returns must be representable.
The layout of a is any, because
of the annotation on the abstract type declaration for a.
But the layout of a must be representable, because
it's the type of a function argument.
we must know concretely how to pass a function argument.
|}]

(**************************************************)
Expand Down
4 changes: 2 additions & 2 deletions ocaml/testsuite/tests/typing-layouts/basics.ml
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ Error: This expression has type t_any but an expression was expected of type
The layout of t_any is any, because
of the definition of t_any at line 5, characters 0-18.
But the layout of t_any must be representable, because
it's the type of a function result.
we must know concretely how to return a function result.
|}];;

let f1 (x : t_any) = ();;
Expand All @@ -377,7 +377,7 @@ Error: This pattern matches values of type t_any
The layout of t_any is any, because
of the definition of t_any at line 5, characters 0-18.
But the layout of t_any must be representable, because
it's the type of a function argument.
we must know concretely how to pass a function argument.
|}];;

(*****************************************************)
Expand Down
4 changes: 2 additions & 2 deletions ocaml/testsuite/tests/typing-layouts/basics_alpha.ml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ Error: This expression has type t_any but an expression was expected of type
The layout of t_any is any, because
of the definition of t_any at line 1, characters 0-18.
But the layout of t_any must be representable, because
it's the type of a function result.
we must know concretely how to return a function result.
|}];;

let f1 (x : t_any) = ();;
Expand All @@ -118,7 +118,7 @@ Error: This pattern matches values of type t_any
The layout of t_any is any, because
of the definition of t_any at line 1, characters 0-18.
But the layout of t_any must be representable, because
it's the type of a function argument.
we must know concretely how to pass a function argument.
|}];;

(*****************************************************)
Expand Down
2 changes: 1 addition & 1 deletion ocaml/testsuite/tests/typing-layouts/modules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ Error: Function arguments and returns must be representable.
The layout of X.t is any, because
of the definition of t at line 2, characters 2-14.
But the layout of X.t must be representable, because
it's the type of a function argument.
we must know concretely how to pass a function argument.
|}]

(***********************************)
Expand Down
6 changes: 4 additions & 2 deletions ocaml/typing/jkind.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1219,8 +1219,10 @@ end = struct
| Record_assignment ->
fprintf ppf "it's the record type used in an assignment"
| Let_binding -> fprintf ppf "it's the type of a variable bound by a `let`"
| Function_argument -> fprintf ppf "it's the type of a function argument"
| Function_result -> fprintf ppf "it's the type of a function result"
| Function_argument ->
fprintf ppf "we must know concretely how to pass a function argument"
| Function_result ->
fprintf ppf "we must know concretely how to return a function result"
| Structure_item_expression ->
fprintf ppf "it's the type of an expression in a structure"
| External_argument ->
Expand Down