Elixir 1.3.0-rc1 compiler can't compile one of my macros. It was okay in Elixir 1.2.6.
defmodule M do
defmacro ifa(a, exp) do
if (Macro.expand_once(a, __ENV__)), do: exp
end
end
defmodule Foo do
@flag true
require M
def main do
M.ifa (@flag), do: IO.puts 123
end
end
Foo.main
The compiler complains about the attribute.
% /tmp/elixir-1.3.0-rc1/bin/elixir foobar.exs
** (ArgumentError) could not call get_attribute on module M because it was already compiled
(elixir) lib/module.ex:1144: Module.assert_not_compiled!/2
(elixir) lib/module.ex:1066: Module.get_attribute/3
(elixir) lib/kernel.ex:2360: Kernel.do_at/4
(elixir) expanding macro: Kernel.@/1
foobar.exs:12: M.ifa/2
expanding macro: M.ifa/2
foobar.exs:12: Foo.main/0
% /tmp/elixir-1.2.6/bin/elixir foobar.exs
123
I wonder why Foo is compiled before expanding the macro. What is changed in 1.3?