L1326 - Variable Exported from Subexpression
Warning
foo() ->
bar(X = baz()),
%% ^ warning: variable X exported from call
X.
Explanation
Variables bound inside subexpressions like function call arguments, tuple elements, list elements, map values, and operator operands are "exported" from those constructs. This is deprecated and may become an error in a future version of Erlang/OTP.
Move the binding out of the subexpression:
%% Instead of:
foo() ->
bar(X = baz()),
X.
%% Write:
foo() ->
X = baz(),
bar(X),
X.
Block expressions (begin, if, case, receive, try, maybe) are not
affected by this warning — exporting variables from those constructs remains valid.
This warning can be suppressed with -compile(nowarn_export_var_subexpr).