No CompileError for using a macro from a Module not yet required

In Elixir 1.2.X trying to use a Macro from a Module which isn’t yet required was giving CompileError as (CompileError) somemodule.exs:XX: you must require Somemodule before invoking themacro Somemodule.something/X

Today I was using a macro from a module and I forgot to require the module, but it didn’t gave CompileError. Later when I tried to use that macro, it gave an UndefinedFunctionError as (UndefinedFunctionError) function Somemodule.something/X is undefined or private. However there is a macro with the same name and arity. Be sure to require Somemodule if you intend to invoke this macro.

When I tracked back, the behavior is changed somewhere in Elixir 1.3.X.

I think the previous behavior was better. But may be the behavior is changed for some good reason, which I don’t know.

The previous behaviour would always attempt to load modules. This means that, whenever you called anything on a given module Mod, we would attempt to load it in the chance it was a macro. But we cannot always load all modules during compilation, for example modules that execute something during on_load.

The error message was just a safety net that we couldn’t always guarantee. You always had/have to require a module before using its macros.


Also I suppose if you couldn’t load the module you don’t really know what that meant. It could have been spelling mistake, or the module hasn’t been compiled yet, or that it is actually a function you are meaning to call.