[erlang-bugs] Compiler/linter bug breaking unused variable warnings

Anders.Ramsell@REDACTED Anders.Ramsell@REDACTED
Wed May 29 20:02:23 CEST 2013


When a function creates a record and more than one field is bound to the value of a list comprehension the compiler/linter fails to generate warnings for unused variables in that function. I just tested this on R16B and the problem is still there.

I use the following module to test this:

--8<----------------------------------------------------------
-module(missing_warning).

-export([test_missing_warning/2,
         test_with_warning1/2,
         test_with_warning2/2
        ]).

-record(data, {aList, bList}).

test_missing_warning(Data, KeyList) -> %% Data never used - no warning.
    KeyList2 = filter(KeyList), %% KeyList2 never used - no warning.
    #data{aList = [Key || Key <- KeyList],
          bList = [Key || Key <- KeyList]}.

test_with_warning1(Data, KeyList) -> %% Data never used - get warning.
    KeyList2 = filter(KeyList), %% KeyList2 never used - get warning.
    #data{aList = [Key || Key <- KeyList]}. %% Only one LC in the record.

test_with_warning2(Data, KeyList) -> %% Data never used - get warning.
    KeyList2 = filter(KeyList), %% KeyList2 never used - get warning.
    {data,
     [Key || Key <- KeyList], %% Not in a record. 
     [Key || Key <- KeyList]}.

filter(L) -> L.
--8<----------------------------------------------------------

In all three test functions the variables Data (in the function head) and KeyList2 (in the function body) are unused.
Compiling the module should produce six warnings but I only get four.
You get the same result with other "advanced" calls like
	lists:map(fun(Key) -> Key end, KeyList)
so it's not limited to list comprehensions.
If the fields are bound to e.g. the variable KeyList directly the warnings work just fine.

/Anders




More information about the erlang-bugs mailing list