How does GenServer (and any other use injections) overriding work from a metaprogramming standpoint?

Given that use GenServer calls for the injection of the AST constructed in the __using__ function of GenServer, and given that this call is typically placed quite early in the module, and there doesn’t seem to be obvious deferment of this call, why can I override the behaviour callbacks with my own implementations?

I understand that module level expressions are evaluated before macro expansion, but def is a macro, so I’m still a bit unclear here.

EDIT: Sorry just to clarify, I conflated behaviours and use, I’m updating in the main post so that future posted are not perturbed by this error on my part.

What behaviour do you intend to override?

That’s what defoverridable does:

Makes the given definitions in the current module overridable.

If the user defines a new function or macro with the same name and arity, then the overridable ones are discarded. Otherwise, the original definitions are used.

2 Likes

Thanks, there was a missing piece to the picture I had.