Skip to content

Commit a4429ac

Browse files
committed
Do not crash on imports inside nested quotes, closes #13575
1 parent f9263fd commit a4429ac

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

lib/elixir/src/elixir_quote.erl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -399,14 +399,14 @@ do_quote(Other, _, _) ->
399399
import_meta(Meta, Name, Arity, Q, E) ->
400400
case (keyfind(imports, Meta) == false) andalso
401401
elixir_dispatch:find_imports(Meta, Name, E) of
402-
[] ->
402+
[_ | _] = Imports ->
403+
keystore(imports, keystore(context, Meta, Q#elixir_quote.context), Imports);
404+
405+
_ ->
403406
case (Arity == 1) andalso keyfind(ambiguous_op, Meta) of
404407
{ambiguous_op, nil} -> keystore(ambiguous_op, Meta, Q#elixir_quote.context);
405408
_ -> Meta
406-
end;
407-
408-
Imports ->
409-
keystore(imports, keystore(context, Meta, Q#elixir_quote.context), Imports)
409+
end
410410
end.
411411

412412
%% do_quote_*

lib/elixir/test/elixir/kernel/quote_test.exs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ defmodule Kernel.QuoteTest do
120120
assert {:quote, _, [[do: {:unquote, _, _}]]} = quote(do: quote(do: unquote(x)))
121121
end
122122

123+
test "import inside nested quote" do
124+
# Check that we can evaluate imports from quote inside quote
125+
assert {{:to_string, meta, [123]}, _} = Code.eval_quoted(quote(do: quote(do: to_string(123))))
126+
assert meta[:imports] == [{1, Kernel}]
127+
end
128+
123129
defmacrop nested_quote_in_macro do
124130
x = 1
125131

0 commit comments

Comments
 (0)