Skip to content

Commit 3854728

Browse files
lukaszsamsonjosevalim
authored andcommitted
Fix parser crash on missing parentheses on expression following operator \"not in\" warning (#15011)
1 parent 4f07670 commit 3854728

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lib/elixir/src/elixir_parser.yrl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,6 +1298,14 @@ warn_pipe(_Token, _) ->
12981298
ok.
12991299

13001300
%% TODO: Make this an error on v2.0
1301+
warn_no_parens_after_do_op({{in_op, Location, Op, _InLocation}, _}) ->
1302+
{Line, _, _} = Location,
1303+
1304+
warn(
1305+
Line,
1306+
"missing parentheses on expression following operator \"" ++ atom_to_list(Op) ++ "\", "
1307+
"you must add parentheses to avoid ambiguities"
1308+
);
13011309
warn_no_parens_after_do_op({{_Type, Location, Op}, _}) ->
13021310
{Line, _, _} = Location,
13031311

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1953,6 +1953,18 @@ defmodule Kernel.WarningTest do
19531953
)
19541954
end
19551955

1956+
test "do+end with not in operator without explicit parentheses" do
1957+
assert_warn_eval(
1958+
["nofile:3\n", "missing parentheses on expression following operator \"not in\""],
1959+
"""
1960+
quote do
1961+
case do
1962+
end not in no_parens 1, 2
1963+
end
1964+
"""
1965+
)
1966+
end
1967+
19561968
test "variable is being expanded to function call (on_undefined_variable: warn)" do
19571969
capture_io(:stderr, fn ->
19581970
Code.put_compiler_option(:on_undefined_variable, :warn)

0 commit comments

Comments
 (0)