Skip to content

Commit a78f171

Browse files
committed
Fix error message around single quote keywords
1 parent b709865 commit a78f171

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

lib/elixir/src/elixir_tokenizer.erl

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,7 @@ tokenize([$" | T], Line, Column, Scope, Tokens) ->
266266

267267
%% TODO: Remove me in Elixir v2.0
268268
tokenize([$' | T], Line, Column, Scope, Tokens) ->
269-
Message = "single-quoted strings represent charlists. "
270-
"Use ~c\"\" if you indeed want a charlist or use \"\" instead.\n"
271-
"You may run \"mix format --migrate\" to fix this warning automatically.",
272-
NewScope = prepend_warning(Line, Column, Message, Scope),
273-
handle_strings(T, Line, Column + 1, $', NewScope, Tokens);
269+
handle_strings(T, Line, Column + 1, $', Scope, Tokens);
274270

275271
% Operator atoms
276272

@@ -786,7 +782,11 @@ handle_strings(T, Line, Column, H, Scope, Tokens) ->
786782
"number do not require quotes",
787783
[hd(Parts)]
788784
),
789-
prepend_warning(Line, Column, WarnMsg, InterScope);
785+
prepend_warning(Line, Column-1, WarnMsg, InterScope);
786+
787+
false when H =:= $' ->
788+
WarnMsg = "single quotes around keywords are deprecated. Use double quotes instead",
789+
prepend_warning(Line, Column-1, WarnMsg, InterScope);
790790

791791
false ->
792792
InterScope
@@ -814,7 +814,19 @@ handle_strings(T, Line, Column, H, Scope, Tokens) ->
814814
error(Reason, Rest, NewScope, Tokens)
815815
end;
816816

817-
{NewLine, NewColumn, Parts, Rest, NewScope} ->
817+
{NewLine, NewColumn, Parts, Rest, InterScope} ->
818+
NewScope =
819+
case H of
820+
$' ->
821+
Message = "single-quoted strings represent charlists. "
822+
"Use ~c\"\" if you indeed want a charlist or use \"\" instead.\n"
823+
"You may run \"mix format --migrate\" to fix this warning automatically.",
824+
prepend_warning(Line, Column-1, Message, InterScope);
825+
826+
_ ->
827+
InterScope
828+
end,
829+
818830
case unescape_tokens(Parts, Line, Column, NewScope) of
819831
{ok, Unescaped} ->
820832
Token = {string_type(H), {Line, Column - 1, nil}, Unescaped},

lib/elixir/test/elixir/kernel/warning_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ defmodule Kernel.WarningTest do
190190
)
191191

192192
assert_warn_eval(
193-
["nofile:1:3", "found quoted keyword \"foo\" but the quotes are not required"],
193+
["nofile:1:2", "found quoted keyword \"foo\" but the quotes are not required"],
194194
~s/["foo": :bar]/
195195
)
196196

0 commit comments

Comments
 (0)