Skip to content

Commit 9c7edf3

Browse files
author
José Valim
committed
Handle unquote in remote call, closes #8588
1 parent 32825eb commit 9c7edf3

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

lib/elixir/src/elixir_quote.erl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,8 @@ annotate(Tree, _Context) -> Tree.
140140

141141
has_unquotes({unquote, _, [_]}) -> true;
142142
has_unquotes({unquote_splicing, _, [_]}) -> true;
143+
has_unquotes({{'.', _, [_, unquote]}, _, [_]}) -> true;
143144
has_unquotes({Var, _, Ctx}) when is_atom(Var), is_atom(Ctx) -> false;
144-
has_unquotes({Name, _, Args}) when is_atom(Name), is_list(Args) ->
145-
lists:any(fun has_unquotes/1, Args);
146145
has_unquotes({Name, _, Args}) when is_list(Args) ->
147146
has_unquotes(Name) orelse lists:any(fun has_unquotes/1, Args);
148147
has_unquotes({Left, Right}) ->

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

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,24 @@ defmodule Kernel.QuoteTest do
9191
assert nested_quote_in_macro() == 1
9292
end
9393

94-
Enum.each([foo: 1, bar: 2, baz: 3], fn {k, v} ->
95-
def unquote(k)(arg) do
96-
unquote(v) + arg
94+
defmodule Dyn do
95+
for {k, v} <- [foo: 1, bar: 2, baz: 3] do
96+
# Local call unquote
97+
def unquote(k)(), do: unquote(v)
98+
99+
# Remote call unquote
100+
def unquote(k)(arg), do: __MODULE__.unquote(k)() + arg
97101
end
98-
end)
102+
end
99103

100104
test "dynamic definition with unquote" do
101-
assert foo(1) == 2
102-
assert bar(2) == 4
103-
assert baz(3) == 6
105+
assert Dyn.foo() == 1
106+
assert Dyn.bar() == 2
107+
assert Dyn.baz() == 3
108+
109+
assert Dyn.foo(1) == 2
110+
assert Dyn.bar(2) == 4
111+
assert Dyn.baz(3) == 6
104112
end
105113

106114
test "splice on root" do
@@ -287,7 +295,7 @@ defmodule Kernel.QuoteTest.ErrorsTest do
287295
RuntimeError ->
288296
mod = Kernel.QuoteTest.ErrorsTest
289297
file = __ENV__.file |> Path.relative_to_cwd() |> String.to_charlist()
290-
assert [{^mod, :will_raise, 2, [file: ^file, line: 267]} | _] = __STACKTRACE__
298+
assert [{^mod, :will_raise, 2, [file: ^file, line: 275]} | _] = __STACKTRACE__
291299
else
292300
_ -> flunk("expected failure")
293301
end
@@ -300,7 +308,7 @@ defmodule Kernel.QuoteTest.ErrorsTest do
300308
RuntimeError ->
301309
mod = Kernel.QuoteTest.ErrorsTest
302310
file = __ENV__.file |> Path.relative_to_cwd() |> String.to_charlist()
303-
assert [{^mod, _, _, [file: ^file, line: 298]} | _] = __STACKTRACE__
311+
assert [{^mod, _, _, [file: ^file, line: 306]} | _] = __STACKTRACE__
304312
else
305313
_ -> flunk("expected failure")
306314
end

0 commit comments

Comments
 (0)