Skip to content
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
16 changes: 11 additions & 5 deletions lib/elixir/src/elixir_tokenizer.erl
Original file line number Diff line number Diff line change
Expand Up @@ -883,8 +883,18 @@ handle_unary_op(Rest, Line, Column, Kind, Length, Op, Scope, Tokens) ->
Token = {identifier, {Line, Column, nil}, Op},
tokenize(Remaining, NewLine, NewColumn, Scope, [Token | Tokens]);
{Remaining, NewLine, NewColumn} ->
NewScope =
%% TODO: Remove these deprecations on Elixir v2.0
case Op of
'~~~' ->
Msg = "~~~ is deprecated. Use Bitwise.bnot/1 instead for clarity",
prepend_warning(Line, Column, Msg, Scope);
_ ->
Scope
end,

Token = {Kind, {Line, Column, nil}, Op},
tokenize(Remaining, NewLine, NewColumn, Scope, [Token | Tokens])
tokenize(Remaining, NewLine, NewColumn, NewScope, [Token | Tokens])
end.

handle_op([$: | Rest], Line, Column, _Kind, Length, Op, Scope, Tokens) when ?is_space(hd(Rest)) ->
Expand All @@ -904,10 +914,6 @@ handle_op(Rest, Line, Column, Kind, Length, Op, Scope, Tokens) ->
Msg = "^^^ is deprecated. It is typically used as xor but it has the wrong precedence, use Bitwise.bxor/2 instead",
prepend_warning(Line, Column, Msg, Scope);

'~~~' ->
Msg = "~~~ is deprecated. Use Bitwise.bnot/1 instead for clarity",
prepend_warning(Line, Column, Msg, Scope);

'<|>' ->
Msg = "<|> is deprecated. Use another pipe-like operator",
prepend_warning(Line, Column, Msg, Scope);
Expand Down
14 changes: 14 additions & 0 deletions lib/elixir/test/erlang/tokenizer_test.erl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ tokenize_error(String) ->
{error, Error, _, _, _} = elixir_tokenizer:tokenize(String, 1, []),
Error.

tokenize_warnings(String) ->
{ok, _Line, _Column, Warnings, Result, []} = elixir_tokenizer:tokenize(String, 1, []),
{lists:reverse(Result), Warnings}.

type_test() ->
[{int, {1, 1, 1}, "1"},
{type_op, {1, 3, nil}, '::'},
Expand Down Expand Up @@ -279,3 +283,13 @@ sigil_heredoc_test() ->
invalid_sigil_delimiter_test() ->
{[{line, 1}, {column, 1}], "invalid sigil delimiter: ", Message} = tokenize_error("~s\\"),
true = lists:prefix("\"\\\" (column 3, code point U+005C)", lists:flatten(Message)).

deprecated_operators_test() ->
{
[{xor_op, {1, 1, nil}, '^^^'}, {int, {1, 4, 1}, "1"}],
[{{1, 1}, "^^^ is deprecated. It is typically used as xor but it has the wrong precedence, use Bitwise.bxor/2 instead"}]
} = tokenize_warnings("^^^1"),
{
[{unary_op, {1, 1, nil}, '~~~'}, {int, {1, 4, 1}, "1"}],
[{{1, 1}, "~~~ is deprecated. Use Bitwise.bnot/1 instead for clarity"}]
} = tokenize_warnings("~~~1").