I am trying to compile a simple module where I get a module from the config and save it on an attribute.
defmodule Test do
@metrics Application.get_env(:my_app, :metrics_module)
@default_deps %{
count_error: &@metrics.inc/1
}
end
However I cannot even compile the code for I have the following error:
== Compilation error in file lib/worker/worker.ex ==
** (ArgumentError) cannot inject attribute @default_deps into function/macro because cannot escape #Function<0.55850841 in file:lib/worker/worker.ex>. The supported values are: lists, tuples, maps, atoms, numbers, bitstrings, PIDs and remote functions in the format &Mod.fun/arity
(elixir) lib/kernel.ex:2879: Kernel.do_at/5
(elixir) expanding macro: Kernel.@/1
lib/worker/worker.ex:47: Cooper.Worker.find/1
(elixir) lib/kernel/parallel_compiler.ex:208: anonymous fn/4 in Kernel.ParallelCompiler.spawn_workers/6
Why can’t this compile given that my dev.exs
does have that parameter defined?