Skip to content

Commit 3010cd3

Browse files
author
José Valim
committed
Provide better error messages for contextual operators
Such as | and :: Closes #6835
1 parent b6e7fa2 commit 3010cd3

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

lib/elixir/src/elixir_expand.erl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,18 @@ format_error({unsupported_option, Kind, Key}) ->
959959
format_error({options_are_not_keyword, Kind, Opts}) ->
960960
io_lib:format("invalid options for ~s, expected a keyword list, got: ~ts",
961961
[Kind, 'Elixir.Macro':to_string(Opts)]);
962+
format_error({undefined_function, '|', [_, _]}) ->
963+
"misplaced operator |/2\n\n"
964+
"The | operator is typically used between brackets as the cons operator:\n\n"
965+
" [head | tail]\n\n"
966+
"where head is a single element and the tail is the remaining of a list.\n"
967+
"It is also used to update maps and structs, via the %{map | key: value} notation,\n"
968+
"and in typespecs, such as @type and @spec, to express the union of two types";
969+
format_error({undefined_function, '::', [_, _]}) ->
970+
"misplaced operator ::/2\n\n"
971+
"The :: operator is typically used in bitstrings to specify types and sizes of segments:\n\n"
972+
" <<size::32-integer, letter::utf8, rest::binary>>\n\n"
973+
"It is also used in typespecs, such as @type and @spec, to describe inputs and outputs";
962974
format_error({undefined_function, Name, Args}) ->
963975
io_lib:format("undefined function ~ts/~B", [Name, length(Args)]);
964976
format_error({underscored_var_repeat, Name, Kind}) ->

0 commit comments

Comments
 (0)