diff --git a/lib/elixir/src/elixir_tokenizer.erl b/lib/elixir/src/elixir_tokenizer.erl index 0290803970f..33601dbbd2f 100644 --- a/lib/elixir/src/elixir_tokenizer.erl +++ b/lib/elixir/src/elixir_tokenizer.erl @@ -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 @@ -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 diff --git a/lib/elixir/test/elixir/kernel/warning_test.exs b/lib/elixir/test/elixir/kernel/warning_test.exs index 1f0f975adbc..db7999c2cbd 100644 --- a/lib/elixir/test/elixir/kernel/warning_test.exs +++ b/lib/elixir/test/elixir/kernel/warning_test.exs @@ -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( [ diff --git a/lib/elixir/test/erlang/atom_test.erl b/lib/elixir/test/erlang/atom_test.erl index 2f8b42ded7f..812ac321668 100644 --- a/lib/elixir/test/erlang/atom_test.erl +++ b/lib/elixir/test/erlang/atom_test.erl @@ -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)"). @@ -29,7 +29,6 @@ kv_with_interpolation_test() -> quoted_atom_test() -> {'+', []} = eval(":\"+\""), - {'+', []} = eval(":'+'"), {'foo bar', []} = eval(":\"foo bar\""). atom_with_interpolation_test() ->