Describe the bug
When compiling an Erlang program that binds variables with an underscore, a warning is presented that a refered variable is unused, which it is not.
This is a minor issue and one can argue that the programmer should not use underscore variables to bind values. However, it may be that in the underlying code something strange is going on that leads to more serious issues later on.
To Reproduce
The following program
-module(nowarning).
-export([f/1]).
f(Acc) ->
X = 0,
{Y} =
begin
_Fresh1 = {[X | Acc]},
_Fresh1
end,
Y.
Results in
> erlc src/nowarning.erl
src/nowarning.erl:6:7: Warning: a term is constructed, but never used
% 6| X = 0,
% | ^
Expected behavior
Since X is used, the error is misleading.
Affected versions
This has been in the compiler for a long time, The following versions I tried it on and they all issue the incorrect warning.
OTP 28.5
OTP-28.5.0.5
OTP-29.0.2
OTP-27.2.3
OTP-25.3.2.13
Additional context
One would expect this to no depend on what X is bound to, but the following program does correctly not produce any warning:
-module(nowarning).
-export([g/1]).
g(Acc) ->
X = foo,
{Y} =
begin
_Fresh1 = {[X | Acc]},
_Fresh1
end,
Y.
Whereas we suspect the _ to be the problem, because the following program is correctly warning free:
-module(nowarning).
-export([h/1]).
h(Acc) ->
X = 0,
{Y} =
begin
Fresh1 = {[X | Acc]},
Fresh1
end,
Y.
Describe the bug
When compiling an Erlang program that binds variables with an underscore, a warning is presented that a refered variable is unused, which it is not.
This is a minor issue and one can argue that the programmer should not use underscore variables to bind values. However, it may be that in the underlying code something strange is going on that leads to more serious issues later on.
To Reproduce
The following program
Results in
Expected behavior
Since
Xis used, the error is misleading.Affected versions
This has been in the compiler for a long time, The following versions I tried it on and they all issue the incorrect warning.
OTP 28.5
OTP-28.5.0.5
OTP-29.0.2
OTP-27.2.3
OTP-25.3.2.13
Additional context
One would expect this to no depend on what
Xis bound to, but the following program does correctly not produce any warning:Whereas we suspect the
_to be the problem, because the following program is correctly warning free: