Skip to content

Commit 2013e93

Browse files
authored
Add warnings on function exported and optional callback (#14552)
1 parent 8442f69 commit 2013e93

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

lib/elixir/lib/kernel.ex

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4515,9 +4515,14 @@ defmodule Kernel do
45154515
Returns `true` if `module` is loaded and contains a
45164516
public `function` with the given `arity`, otherwise `false`.
45174517
4518-
Note that this function does not load the module in case
4519-
it is not loaded. Check `Code.ensure_loaded/1` for more
4520-
information.
4518+
> ### Unloaded modules {: .warning }
4519+
>
4520+
> This function does *not* load the module in case it is not loaded
4521+
> and Elixir lazily loads modules by default (except on releases).
4522+
> This may yield unexpected results in testing when module
4523+
> usage order is random.
4524+
>
4525+
> See `Code.ensure_loaded/1` for more information.
45214526
45224527
Inlined by the compiler.
45234528

lib/elixir/pages/references/typespecs.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,11 @@ Note you don't need to define a behaviour in order to dynamically dispatch on a
388388

389389
Optional callbacks are callbacks that callback modules may implement if they want to, but are not required to. Usually, behaviour modules know if they should call those callbacks based on configuration, or they check if the callbacks are defined with `function_exported?/3` or `macro_exported?/3`.
390390

391+
> Testing Optional Callbacks {: .warning }
392+
>
393+
> `mix test` may exhibit unexpected behaviour when testing a conditional call to an optional callback gated
394+
> on `function_exported?/3`, see the documentation on this function for details.
395+
391396
Optional callbacks can be defined through the `@optional_callbacks` module attribute, which has to be a keyword list with function or macro name as key and arity as value. For example:
392397

393398
defmodule MyBehaviour do

0 commit comments

Comments
 (0)