Skip to content

Commit b5941d2

Browse files
michallepickijosevalim
authored andcommitted
Expand default compile_env argument in expand literals (#12181)
1 parent 5f20a94 commit b5941d2

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

lib/elixir/lib/macro.ex

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2053,6 +2053,16 @@ defmodule Macro do
20532053
:lists.mapfoldl(&expand_literals(&1, &2, fun), acc, list)
20542054
end
20552055

2056+
def expand_literals(
2057+
{{:., _, [{:__aliases__, _, [:Application]}, :compile_env]} = node, meta,
2058+
[app, key, default]},
2059+
acc,
2060+
fun
2061+
) do
2062+
{default, acc} = expand_literals(default, acc, fun)
2063+
{{node, meta, [app, key, default]}, acc}
2064+
end
2065+
20562066
def expand_literals(term, acc, _fun), do: {term, acc}
20572067

20582068
@doc """

lib/elixir/test/elixir/kernel/lexical_tracker_test.exs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,18 @@ defmodule Kernel.LexicalTrackerTest do
226226

227227
assert String in compile
228228
assert Enum in compile
229+
230+
{{compile, _, _, _}, _binding} =
231+
Code.eval_string("""
232+
defmodule Kernel.LexicalTrackerTest.Attribute6 do
233+
@example %{foo: Application.compile_env(:elixir, Enum, String)}
234+
def foo(atom) when atom == @example.foo, do: atom
235+
Kernel.LexicalTracker.references(__ENV__.lexical_tracker)
236+
end |> elem(3)
237+
""")
238+
239+
refute String in compile
240+
refute Enum in compile
229241
end
230242

231243
test "@compile adds a runtime dependency" do

0 commit comments

Comments
 (0)