Skip to main content

W0095 - Used ignored variable

Example​

handle(_Request, State) ->
log(_Request),
%% ^^^^^^^^ warning: W0095: Variable `_Request` is used, but its leading `_` marks it as ignored.
State.

Explanation​

A leading _ tells the compiler and readers that a variable is intentionally unused: the compiler does not warn when it is never used. Using such a variable breaks the convention: readers skip it as irrelevant, and if the use is later removed, the compiler stays silent about the now unused variable.

A pattern that contains an already-bound _Name variable matches its value, so it is a use too.

Variables introduced by macro definitions, such as the __X names some assertion macros use, are not reported.

Variables passed as macro arguments are not reported either: whether a macro uses an argument can depend on the macros defined at compile time, as with a logging macro that discards its arguments unless TEST is defined.

Fix​

Drop the leading _ from every occurrence of the variable in the function clause, picking another name if the new one is already used there.

handle(Request, State) ->
log(Request),
State.