Skip to content

Add context to error message when unit is expected #7045

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
add some context to error message when unit is expected
  • Loading branch information
zth committed Sep 21, 2024
commit 3bbde1a89cf252a05dfc5631da22fbbcf68a9312
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@
8 │ }

This function call returns: string
But it's expected to return: unit
But it's expected to return: unit

- Did you mean to assign this to a variable?
- If you don't care about the result of this expression, you can assign it to _ via let _ = ... or pipe it to ignore via expression->ignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@
4 │ }

This has type: int
But it's expected to have type: unit
But it's expected to have type: unit

- Did you mean to assign this to a variable?
- If you don't care about the result of this expression, you can assign it to _ via let _ = ... or pipe it to ignore via expression->ignore
9 changes: 9 additions & 0 deletions jscomp/ml/error_message_utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,15 @@ let print_extra_type_clash_help ppf trace type_clash_context =
\ - Use a tuple, if your array is of fixed length. Tuples can mix types \
freely, and compiles to a JavaScript array. Example of a tuple: `let \
myTuple = (10, \"hello\", 15.5, true)"
| ( _,
[
({Types.desc = Tconstr (_p1, _, _)}, _); ({desc = Tconstr (p2, _, _)}, _);
] )
when Path.same Predef.path_unit p2 ->
fprintf ppf
"\n\n\
\ - Did you mean to assign this to a variable?\n\
\ - If you don't care about the result of this expression, you can assign it to @{<info>_@} via @{<info>let _ = ...@} or pipe it to @{<info>ignore@} via @{<info>expression->ignore@}\n\n"
| _ -> ()

let type_clash_context_from_function sexp sfunct =
Expand Down
Loading