Skip to content

Commit cb0f900

Browse files
author
José Valim
committed
Document defoverridable behaviour regarding compilation callbacks
Closes #7340 Signed-off-by: José Valim <[email protected]>
1 parent 815420c commit cb0f900

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

lib/elixir/lib/module.ex

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,8 @@ defmodule Module do
297297
When just a module is provided, the function is assumed to be
298298
`__after_compile__/2`.
299299
300+
Callbacks registered first will run last.
301+
300302
#### Example
301303
302304
defmodule MyModule do
@@ -312,13 +314,18 @@ defmodule Module do
312314
A hook that will be invoked before the module is compiled.
313315
314316
Accepts a module or a `{module, function_or_macro_name}` tuple. The
315-
function/macro must take one argument: the module environment. If it's a
316-
macro, its returned value will be injected at the end of the module definition
317-
before the compilation starts.
317+
function/macro must take one argument: the module environment. If
318+
it's a macro, its returned value will be injected at the end of the
319+
module definition before the compilation starts.
318320
319321
When just a module is provided, the function/macro is assumed to be
320322
`__before_compile__/1`.
321323
324+
Callbacks registered first will run last. Any overridable definition
325+
will be made concrete before the first callback runs. A definition may
326+
be made overridable again in another before compile callback and it
327+
will be made concrete one last time after after all callbacks run.
328+
322329
*Note*: unlike `@after_compile`, the callback function/macro must
323330
be placed in a separate module (because when the callback is invoked,
324331
the current module does not yet exist).

0 commit comments

Comments
 (0)