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
20 changes: 18 additions & 2 deletions lib/elixir/src/elixir_tokenizer.erl
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,15 @@ tokenize([T | Rest], Line, Column, Scope, Tokens) when ?pipe_op(T) ->

% Non-operator Atoms

tokenize([$:, H | T] = Original, Line, Column, Scope, Tokens) when ?is_quote(H) ->
tokenize([$:, H | T] = Original, Line, Column, BaseScope, Tokens) when ?is_quote(H) ->
Scope = case H == $' of
true ->
prepend_warning(Line, Column, "single quotes around atoms are deprecated. Use double quotes instead", BaseScope);

false ->
BaseScope
end,

case elixir_interpolation:extract(Line, Column + 2, Scope, true, T, H) of
{NewLine, NewColumn, Parts, Rest, InterScope} ->
NewScope = case is_unnecessary_quote(Parts, InterScope) of
Expand Down Expand Up @@ -896,7 +904,15 @@ handle_dot([$., $( | Rest], Line, Column, DotInfo, Scope, Tokens) ->
TokensSoFar = add_token_with_eol({dot_call_op, DotInfo, '.'}, Tokens),
tokenize([$( | Rest], Line, Column, Scope, TokensSoFar);

handle_dot([$., H | T] = Original, Line, Column, DotInfo, Scope, Tokens) when ?is_quote(H) ->
handle_dot([$., H | T] = Original, Line, Column, DotInfo, BaseScope, Tokens) when ?is_quote(H) ->
Scope = case H == $' of
true ->
prepend_warning(Line, Column, "single quotes around calls are deprecated. Use double quotes instead", BaseScope);

false ->
BaseScope
end,

case elixir_interpolation:extract(Line, Column + 1, Scope, true, T, H) of
{NewLine, NewColumn, [Part], Rest, InterScope} when is_list(Part) ->
NewScope = case is_unnecessary_quote([Part], InterScope) of
Expand Down
36 changes: 36 additions & 0 deletions lib/elixir/test/elixir/kernel/warning_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,42 @@ defmodule Kernel.WarningTest do
end
end

describe "deprecated single quotes in atoms" do
test "warns for single quotes in atoms" do
assert_warn_eval(
[
"nofile:1:1",
"single quotes around atoms are deprecated. Use double quotes instead"
],
~s/:'a+b'/
)
end

test "warns twice for single and unnecessary atom quotes" do
assert_warn_eval(
[
"nofile:1:1",
"single quotes around atoms are deprecated. Use double quotes instead",
"nofile:1:1",
"found quoted atom \"ab\" but the quotes are not required"
],
~s/:'ab'/
)
end

test "warns twice for single and unnecessary call quotes" do
assert_warn_eval(
[
"nofile:1:9",
"single quotes around calls are deprecated. Use double quotes instead",
"nofile:1:9",
"found quoted call \"length\" but the quotes are not required"
],
~s/[Kernel.'length'([])]/
)
end
end

test "warns on :: as atom" do
assert_warn_eval(
[
Expand Down
3 changes: 1 addition & 2 deletions lib/elixir/test/erlang/atom_test.erl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ atom_with_punctuation_test() ->
{'...', []} = eval(":...").

atom_quoted_call_test() ->
{3, []} = eval("Kernel.'+'(1, 2)").
{3, []} = eval("Kernel.\"+\"(1, 2)").

kv_with_quotes_test() ->
{'foo bar', []} = eval(":atom_test.kv(\"foo bar\": nil)").
Expand All @@ -29,7 +29,6 @@ kv_with_interpolation_test() ->

quoted_atom_test() ->
{'+', []} = eval(":\"+\""),
{'+', []} = eval(":'+'"),
{'foo bar', []} = eval(":\"foo bar\"").

atom_with_interpolation_test() ->
Expand Down
Loading