Skip to content

Commit 50266c4

Browse files
committed
Fix regression on grammar, closes #12579
1 parent ad3f7d2 commit 50266c4

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

lib/elixir/src/elixir_parser.yrl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ matched_expr -> access_expr kw_identifier : error_invalid_kw_identifier('$2').
153153
unmatched_expr -> matched_expr unmatched_op_expr : build_op('$1', '$2').
154154
unmatched_expr -> unmatched_expr matched_op_expr : build_op('$1', '$2').
155155
unmatched_expr -> unmatched_expr unmatched_op_expr : build_op('$1', '$2').
156+
unmatched_expr -> unmatched_expr no_parens_op_expr : warn_no_parens_after_do_op('$2'), build_op('$1', '$2').
156157
unmatched_expr -> unary_op_eol expr : build_unary_op('$1', '$2').
157158
unmatched_expr -> at_op_eol expr : build_unary_op('$1', '$2').
158159
unmatched_expr -> capture_op_eol expr : build_unary_op('$1', '$2').
@@ -1218,6 +1219,16 @@ warn_pipe({arrow_op, {Line, Column, _}, Op}, {_, [_ | _], [_ | _]}) ->
12181219
warn_pipe(_Token, _) ->
12191220
ok.
12201221

1222+
%% TODO: Make this an error on v2.0
1223+
warn_no_parens_after_do_op({{_Type, Location, Op}, _}) ->
1224+
{Line, _, _} = Location,
1225+
1226+
warn(
1227+
Line,
1228+
"missing parentheses on expression following operator \"" ++ atom_to_list(Op) ++ "\", "
1229+
"you must add parentheses to avoid ambiguities"
1230+
).
1231+
12211232
%% TODO: Make this an error on v2.0
12221233
warn_nested_no_parens_keyword(Key, Value) when is_atom(Key) ->
12231234
{line, Line} = lists:keyfind(line, 1, ?meta(Value)),

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,6 +1647,17 @@ defmodule Kernel.WarningTest do
16471647
end) =~ "missing parentheses for expression following \"label:\" keyword. "
16481648
end
16491649

1650+
test "do+end with operator without explicit parentheses" do
1651+
assert capture_err(fn ->
1652+
Code.eval_string("""
1653+
quote do
1654+
case do
1655+
end || raise 1, 2
1656+
end
1657+
""")
1658+
end) =~ "missing parentheses on expression following operator \"||\""
1659+
end
1660+
16501661
test "variable is being expanded to function call (on_undefined_variable: warn)" do
16511662
Code.put_compiler_option(:on_undefined_variable, :warn)
16521663

0 commit comments

Comments
 (0)