Skip to content

Commit a09fa10

Browse files
authored
Fix parser crash on missing parentheses on expression following operator \"not in\" warning (#15011)
1 parent 0b3dc13 commit a09fa10

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
@@ -1295,6 +1295,14 @@ warn_pipe(_Token, _) ->
12951295
ok.
12961296

12971297
%% TODO: Make this an error on v2.0
1298+
warn_no_parens_after_do_op({{in_op, Location, Op, _InLocation}, _}) ->
1299+
{Line, _, _} = Location,
1300+
1301+
warn(
1302+
Line,
1303+
"missing parentheses on expression following operator \"" ++ atom_to_list(Op) ++ "\", "
1304+
"you must add parentheses to avoid ambiguities"
1305+
);
12981306
warn_no_parens_after_do_op({{_Type, Location, Op}, _}) ->
12991307
{Line, _, _} = Location,
13001308

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)