Skip to content

Commit 3d3453c

Browse files
committed
Do not emit warnings on Cursor.Fragment.container_cursor_to_quoted/2
1 parent 2dc3fd2 commit 3d3453c

File tree

4 files changed

+32
-17
lines changed

4 files changed

+32
-17
lines changed

lib/elixir/lib/code/fragment.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ defmodule Code.Fragment do
827827

828828
case :elixir_tokenizer.tokenize(fragment, line, column, tokenizer_opts) do
829829
{:ok, _, _, _warnings, tokens} ->
830-
:elixir.tokens_to_quoted(tokens, file, columns: columns, token_metadata: token_metadata)
830+
:elixir.tokens_to_quoted(tokens, nil, columns: columns, token_metadata: token_metadata)
831831

832832
{:error, {line, column, {prefix, suffix}, token}, _rest, _warnings, _so_far} ->
833833
location = [line: line, column: column]

lib/elixir/src/elixir.erl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,8 @@ string_to_tokens(String, StartLine, StartColumn, File, Opts) when is_integer(Sta
359359
{error, {Location, to_binary(Error), to_binary(Token)}}
360360
end.
361361

362-
tokens_to_quoted(Tokens, File, Opts) ->
363-
handle_parsing_opts(File, Opts),
362+
tokens_to_quoted(Tokens, WarningFile, Opts) ->
363+
handle_parsing_opts(WarningFile, Opts),
364364

365365
try elixir_parser:parse(Tokens) of
366366
{ok, Forms} ->
@@ -370,7 +370,7 @@ tokens_to_quoted(Tokens, File, Opts) ->
370370
{error, {Line, _, [Error, Token]}} ->
371371
{error, {parser_location(Line), to_binary(Error), to_binary(Token)}}
372372
after
373-
erase(elixir_parser_file),
373+
erase(elixir_parser_warning_file),
374374
erase(elixir_parser_columns),
375375
erase(elixir_token_metadata),
376376
erase(elixir_literal_encoder)
@@ -406,15 +406,15 @@ parser_location(Meta) ->
406406
to_binary(List) when is_list(List) -> elixir_utils:characters_to_binary(List);
407407
to_binary(Atom) when is_atom(Atom) -> atom_to_binary(Atom, utf8).
408408

409-
handle_parsing_opts(File, Opts) ->
409+
handle_parsing_opts(WarningFile, Opts) ->
410410
LiteralEncoder =
411411
case lists:keyfind(literal_encoder, 1, Opts) of
412412
{literal_encoder, Fun} -> Fun;
413413
false -> false
414414
end,
415415
TokenMetadata = lists:keyfind(token_metadata, 1, Opts) == {token_metadata, true},
416416
Columns = lists:keyfind(columns, 1, Opts) == {columns, true},
417-
put(elixir_parser_file, File),
417+
put(elixir_parser_warning_file, WarningFile),
418418
put(elixir_parser_columns, Columns),
419419
put(elixir_token_metadata, TokenMetadata),
420420
put(elixir_literal_encoder, LiteralEncoder).

lib/elixir/src/elixir_parser.yrl

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,6 @@ map -> struct_op struct_expr eol map_args : {'%', meta_from_token('$1'), ['$2',
640640

641641
Erlang code.
642642

643-
-define(file(), get(elixir_parser_file)).
644643
-define(columns(), get(elixir_parser_columns)).
645644
-define(token_metadata(), get(elixir_token_metadata)).
646645

@@ -729,10 +728,12 @@ build_op(AST, {_Kind, Location, '//'}, Right) ->
729728

730729
build_op({UOp, _, [Left]}, {_Kind, {Line, Column, _} = Location, 'in'}, Right) when ?rearrange_uop(UOp) ->
731730
%% TODO: Remove "not left in right" rearrangement on v2.0
732-
elixir_errors:erl_warn({Line, Column}, ?file(),
731+
warn(
732+
{Line, Column},
733733
"\"not expr1 in expr2\" is deprecated. "
734734
"Instead use \"expr1 not in expr2\" if you require Elixir v1.5+, "
735-
"or \"not(expr1 in expr2)\" if you have to support earlier Elixir versions"),
735+
"or \"not(expr1 in expr2)\" if you have to support earlier Elixir versions"
736+
),
736737
Meta = meta_from_location(Location),
737738
{UOp, Meta, [{'in', Meta, [Left, Right]}]};
738739

@@ -1169,21 +1170,22 @@ error_invalid_kw_identifier({_, Location, KW}) ->
11691170

11701171
%% TODO: Make this an error on v2.0
11711172
warn_trailing_comma({',', {Line, Column, _}}) ->
1172-
elixir_errors:erl_warn({Line, Column}, ?file(),
1173-
"trailing commas are not allowed inside function/macro call arguments"
1174-
).
1173+
warn({Line, Column}, "trailing commas are not allowed inside function/macro call arguments").
11751174

11761175
%% TODO: Make this an error on v2.0
11771176
warn_empty_paren({_, {Line, Column, _}}) ->
1178-
elixir_errors:erl_warn({Line, Column}, ?file(),
1177+
warn(
1178+
{Line, Column},
11791179
"invalid expression (). "
11801180
"If you want to invoke or define a function, make sure there are "
11811181
"no spaces between the function name and its arguments. If you wanted "
1182-
"to pass an empty block or code, pass a value instead, such as a nil or an atom").
1182+
"to pass an empty block or code, pass a value instead, such as a nil or an atom"
1183+
).
11831184

11841185
%% TODO: Make this an error on v2.0
11851186
warn_pipe({arrow_op, {Line, Column, _}, Op}, {_, [_ | _], [_ | _]}) ->
1186-
elixir_errors:erl_warn({Line, Column}, ?file(),
1187+
warn(
1188+
{Line, Column},
11871189
io_lib:format(
11881190
"parentheses are required when piping into a function call. For example:\n\n"
11891191
" foo 1 ~ts bar 2 ~ts baz 3\n\n"
@@ -1197,6 +1199,14 @@ warn_pipe(_Token, _) ->
11971199
ok.
11981200

11991201
warn_empty_stab_clause({stab_op, {Line, Column, _}, '->'}) ->
1200-
elixir_errors:erl_warn({Line, Column}, ?file(),
1202+
warn(
1203+
{Line, Column},
12011204
"an expression is always required on the right side of ->. "
1202-
"Please provide a value after ->").
1205+
"Please provide a value after ->"
1206+
).
1207+
1208+
warn(LineColumn, Message) ->
1209+
case get(elixir_parser_warning_file) of
1210+
nil -> ok;
1211+
File -> elixir_errors:erl_warn(LineColumn, File, Message)
1212+
end.

lib/elixir/test/elixir/code_fragment_test.exs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,11 @@ defmodule CodeFragmentTest do
915915
assert cc2q("foo(123, ~r/") == s2q("foo(123, __cursor__())")
916916
end
917917

918+
test "no warnings" do
919+
assert cc2q(~s"?\\ ") == s2q("__cursor__()")
920+
assert cc2q(~s"{fn -> end, ") == s2q("{fn -> nil end, __cursor__()}")
921+
end
922+
918923
test "options" do
919924
opts = [columns: true]
920925
assert cc2q("foo(", opts) == s2q("foo(__cursor__())", opts)

0 commit comments

Comments
 (0)