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

Anthony Ramine n.oxyde@REDACTED
Tue Jul 23 09:27:57 CEST 2013


Hello,

I've added a commit to the branch that fix the bug discovered with Paul Davis where used variables in try expressions aren't properly marked as unsafe.

Please refetch.

-- 
Anthony Ramine

Le 1 juil. 2013 à 19:30, Anthony Ramine a écrit :

> Hi Fredrik,
> 
> I've amended the commit message and gave an example of a simpler expression triggering the bug, e.g.:
> 
> t(X, Y) ->
>  {A=X,A=Y}.
> 
> As for the vt_no_unused/1 call in expr_list/1, it is a mistake as Vt1 comes from the variable tables returned by expr/3 in the lists:foldl/3 call, which means it can't contain any old variable which was unused anyway.
> 
> Regards,
> 
> -- 
> Anthony Ramine
> 
> Le 1 juil. 2013 à 11:23, Fredrik a écrit :
> 
>> On 06/06/2013 01:47 AM, Anthony Ramine wrote:
>>> Hello,
>>> 
>>> When analyzing complex expressions (i.e. comprehensions, cases, tries, ifs and receives), erl_lint does not forget about old unused variables when returning the updated variable table. This causes a bug where old
>>> unused variables are not recorded as such:
>>> 
>>> t(X, Y) ->
>>>  #r{a=[ K || K <- Y ],b=[ K || K <- Y ].
>>> 
>>> As erl_lint uses vtmerge_pat/2 to merge the results of the analysis of the two list comprehensions, X is marked as used and the warning is not emitted.
>>> 
>>> The function vtmerge_pat/2 is used instead of the similar vtmerge/2 which does not mark multiple occurrences of a variable as usage to handle cases like the following one:
>>> 
>>> t(X, Y) ->
>>>  #r{a=A=X,b=A=Y}.
>>> 
>>> Other simpler expressions like conses, tuples and external fun references does not correctly follow this behaviour.
>>> 
>>> This patch fixes both issues and makes erl_lint not return old unused variables in updated tables and makes all compound expressions use vtmerge_pat/2.
>>> 
>>> 	git fetch 
>>> https://github.com/nox/otp.git
>>> fix-erl_lint-variable-usage
>>> 
>>> 	
>>> https://github.com/nox/otp/compare/erlang:maint...fix-erl_lint-variable-usage
>>> 
>>> 	
>>> https://github.com/nox/otp/compare/erlang:maint...fix-erl_lint-variable-usage.patch
>>> 
>>> 
>>> Regards,
>>> 
>>> 
>> Hi Anthony,
>> Your patch has been reviewed and the feedback was:
>> 
>> "
>> Hi,
>> 
>> The first example of the commit messages lacks a '}' before the dot.
>> 
>> I'm not sure I understand exactly what the paragraph starting with "Other simpler expressions..." means. Could you clarify, please? (And substitute "do" for "does"...)
>> 
>> I noticed that if the call to vt_no_unused() in the last line of expr_list/3 is removed the test suite still passes; there is no case where the call actually removes anything. Would it be possible to include a test that covers this particular call?
>> 
>> Best regards,
>> 
>> "
>> 
>> -- 
>> 
>> BR Fredrik Gustafsson
>> Erlang OTP Team
>> 
> 




More information about the erlang-patches mailing list