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

Anthony Ramine n.oxyde@REDACTED
Fri May 31 00:46:57 CEST 2013


Hello,

Smaller test case reproducing the bug, without KeyList2 nor filter/1:

-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, KeyList never used - no warning.
   #data{aList = [Key || Key <- []],
         bList = [Key || Key <- []]}.

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

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

Regards,

-- 
Anthony Ramine

Le 29 mai 2013 à 20:02, <Anders.Ramsell@REDACTED> <Anders.Ramsell@REDACTED> a écrit :

> 
> 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
> 
> _______________________________________________
> erlang-bugs mailing list
> erlang-bugs@REDACTED
> http://erlang.org/mailman/listinfo/erlang-bugs




More information about the erlang-bugs mailing list