How do I make this work in a defenum
macro?
defenum EmailStatus, :email_status, @email_states
Right now, I’m getting:
warning: undefined module attribute @email_states, please remove access to @email_states or explicitly set it before access
It’s making no difference whether I’m using Macro.expand/2
or not:
values: {:@, [line: 122], [{:email_states, [line: 122], nil}]}
values-expanded: {{:., [],
[
{:__aliases__, [counter: {MyApp.Enum, 9}, alias: false],
[:Module]},
:get_attribute
]}, [],
[
{:__MODULE__, [counter: {MyApp.Enum, 9}], Kernel},
:email_states,
122
]}
I actually want to pass in a value that’s closer to:
@a ~w(a b c d)
@b ~w(e f g h)
@c ~w(I j k l)
defenum EmailStatus, :email_status, @a ++ @b ++ @c
The macro in question is complex, and may eventually be released as a fork of an already existing package. But for the purposes of this test, I believe that this will do:
defmacro defenum(module, type, values) do
quote location: :keep do
defmodule unquote(module) do
@enum_type unquote(type)
@values Enum.map(unquote(values), &to_string/1)
def type, do: @enum_type
def values, do: @values
end
end
end
Ideas?
-a