Skip to content

Commit e36f513

Browse files
committed
Make quote of pipe has same behaviour about hygiene in Imports
elixir-lang#11651
1 parent 1dab831 commit e36f513

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/elixir/src/elixir_quote.erl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,19 @@ do_quote({'&', Meta, [{'/', _, [{F, _, C}, A]}] = Args},
333333
end,
334334
do_quote_tuple('&', NewMeta, Args, Q, E);
335335

336+
do_quote({'|>', M, [B, {F, Meta, As}]},
337+
#elixir_quote{imports_hygiene=true} = Q, E) when is_atom(F), is_list(As) ->
338+
A = length(As) + 1,
339+
NewMeta =
340+
case elixir_dispatch:find_import(Meta, F, A, E) of
341+
false ->
342+
Meta;
343+
344+
Receiver ->
345+
keystore(context, keystore(imports, Meta, [{Receiver, A}]), Q#elixir_quote.context)
346+
end,
347+
do_quote_tuple('|>', M, [B, {F, NewMeta, As}], Q, E);
348+
336349
do_quote({Name, Meta, ArgsOrContext}, #elixir_quote{imports_hygiene=true} = Q, E)
337350
when is_atom(Name), is_list(Meta), is_list(ArgsOrContext) or is_atom(ArgsOrContext) ->
338351
Arity = if

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ defmodule Kernel.QuoteTest do
6969
assert quote(generated: true, do: bar(1)) == {:bar, [generated: true], [1]}
7070
end
7171

72+
test "quote pipe with imports" do
73+
import Integer, only: [is_odd: 1]
74+
q = quote(do: 2 |> is_odd())
75+
assert {false, _} = Code.eval_quoted(q)
76+
end
77+
7278
test "unquote call" do
7379
assert quote(do: foo(bar)[unquote(:baz)]) == quote(do: foo(bar)[:baz])
7480
assert quote(do: unquote(:bar)()) == quote(do: bar())

0 commit comments

Comments
 (0)