Skip to content

Commit 0df110c

Browse files
committed
&Mod.fun/arity are valid app terms, closes #14891
1 parent 22635e6 commit 0df110c

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

lib/mix/lib/mix/tasks/compile.app.ex

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,20 @@ defmodule Mix.Tasks.Compile.App do
239239
[?#, ?{, inner, ?}]
240240
end
241241

242-
defp to_erl_term(term) when is_function(term) or is_reference(term) or is_pid(term) do
242+
defp to_erl_term(function) when is_function(function) do
243+
fun_info = Function.info(function)
244+
245+
if fun_info[:type] == :external and fun_info[:env] == [] do
246+
:io_lib.print(function)
247+
else
248+
Mix.raise(
249+
"\"def application\" has a function which cannot be written to .app files: #{inspect(function)}" <>
250+
" (only functions in the form &Mod.fun/arity can be part of the application environment)"
251+
)
252+
end
253+
end
254+
255+
defp to_erl_term(term) when is_reference(term) or is_pid(term) do
243256
Mix.raise(
244257
"\"def application\" has a term which cannot be written to .app files: #{inspect(term)}"
245258
)

lib/mix/test/mix/tasks/compile.app_test.exs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ defmodule Mix.Tasks.Compile.AppTest do
110110
test "uses custom application settings" do
111111
in_fixture("no_mixfile", fn ->
112112
Mix.Project.push(CustomProject)
113-
env = [foo: [:one, "two", 3, 4, "฿"], bar: [{} | %{foo: :bar}]]
113+
env = [foo: [:one, "two", 3, 4, "฿", &List.flatten/1], bar: [{} | %{foo: :bar}]]
114114

115115
Process.put(:application,
116116
maxT: :infinity,
@@ -132,7 +132,10 @@ defmodule Mix.Tasks.Compile.AppTest do
132132
assert properties[:applications] ==
133133
[:kernel, :stdlib, :elixir, :logger, :ex_unit, :example_app, :mix]
134134

135-
assert properties[:env] == [foo: [:one, "two", 3, 4, "฿"], bar: [{} | %{foo: :bar}]]
135+
assert properties[:env] == [
136+
foo: [:one, "two", 3, 4, "฿", &List.flatten/1],
137+
bar: [{} | %{foo: :bar}]
138+
]
136139

137140
refute Keyword.has_key?(properties, :extra_applications)
138141
end)

0 commit comments

Comments
 (0)