W0098 - Unused callback
Example
-module(my_behaviour).
-export([run/2]).
-callback init(term()) -> ok.
-callback handle(term()) -> ok.
%% ^^^^^^ warning: W0098: Callback `handle/1` is never called.
run(Mod, Arg) ->
Mod:init(Arg).
Explanation
A behaviour declares its callbacks so that the code driving it can call them on whichever module implements the behaviour. A callback that is never called forces every implementation to define a function that does nothing useful, and often means that a feature was removed or never finished.
A callback counts as called when:
- its name appears anywhere in the functions of the behaviour module, for
example
Mod:handle(Arg),apply(Mod, handle, [Arg])orerlang:function_exported(Mod, handle, 1); or - a module of the project calls it dynamically, as
Mod:handle(Arg)orfun Mod:handle/1, where the module is not an atom literal, or passes the atomhandleas an argument to a function, also inside a tuple, list, map or record argument such as{handle, Arg}; or - a module of the project calls functions as
Mod:Fun(...),fun Mod:Fun/N, or through a function taking a module, a function name and arguments, such asapply(Mod, Fun, Args),spawn(Mod, Fun, Args),proc_lib:start_link(Mod, Fun, Args)orrpc:call(Node, Mod, Fun, Args), with both the module and the function unknown, and mentions the atomhandle. These functions are ELP's built-in dynamic call patterns, plus any configured in thedynamic_callssection of.elp_lint.toml.
Macros, including those defined in included headers, are expanded first.
A callback listed in -optional_callbacks is reported on the same terms:
being optional to implement does not make it called.
A callback name that reaches a generic dispatcher only through a variable,
as in Name = handle, dispatcher:call(Mod, Name, Arg), is not seen, so the
callback gets reported.
A behaviour used only to check that some modules export a set of functions, which are then called by their module name, also gets reported: no code calls those callbacks through the behaviour.
Fix
Remove the callback from the behaviour, along with its implementations, or add the missing call.