Skip to content

Commit 514bc86

Browse files
authored
Fix Macro.escape/1 bug when :quote tuples is in the tail of a list (#14775)
Close #14771
1 parent 29e8883 commit 514bc86

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/elixir/src/elixir_quote.erl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,11 @@ do_escape([], _) ->
199199
[];
200200

201201
do_escape([H | T], #elixir_quote{unquote=false} = Q) ->
202-
do_quote_simple_list(T, do_escape(H, Q), Q);
202+
case is_list(T) of
203+
true -> [do_escape(H, Q) | do_escape(T, Q)];
204+
% improper list
205+
false -> [{'|', [], [do_escape(H, Q), do_escape(T, Q)]}]
206+
end;
203207

204208
do_escape([H | T], Q) ->
205209
%% The improper case is inefficient, but improper lists are rare.

lib/elixir/test/elixir/macro_test.exs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ defmodule MacroTest do
149149
test "escapes the content of :quote tuples" do
150150
assert Macro.escape({:quote, [%{}], [{}]}) ==
151151
{:{}, [], [:quote, [{:%{}, [], []}], [{:{}, [], []}]]}
152+
153+
assert Macro.escape([:foo, {:quote, [%{}], [{}]}]) ==
154+
[:foo, {:{}, [], [:quote, [{:%{}, [], []}], [{:{}, [], []}]]}]
152155
end
153156

154157
test "escape container when a reference cannot be escaped" do

0 commit comments

Comments
 (0)