aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnthony Ramine <[email protected]>2013-07-31 10:31:51 +0200
committerFredrik Gustafsson <[email protected]>2013-08-27 16:15:21 +0200
commit92460f4035e369be8726c88a72055d0fd6c7cdfe (patch)
treee6d413e13ba3ddf5b5baf42e1d79105b8dbdc92c
parent9ce148b1059e4da746a11f1d80a653340216c468 (diff)
downloadotp-92460f4035e369be8726c88a72055d0fd6c7cdfe.tar.gz
otp-92460f4035e369be8726c88a72055d0fd6c7cdfe.tar.bz2
otp-92460f4035e369be8726c88a72055d0fd6c7cdfe.zip
Fix variable usage tracking in some record errors
When reporting a field redefinition in a record, erl_lint can forget about some old unused variables. f() -> X = 1, #r{a=foo,a=bar,a=qux}.
-rw-r--r--lib/stdlib/src/erl_lint.erl2
-rw-r--r--lib/stdlib/test/erl_lint_SUITE.erl10
2 files changed, 10 insertions, 2 deletions
diff --git a/lib/stdlib/src/erl_lint.erl b/lib/stdlib/src/erl_lint.erl
index 708ef44fed..f599881c07 100644
--- a/lib/stdlib/src/erl_lint.erl
+++ b/lib/stdlib/src/erl_lint.erl
@@ -2308,7 +2308,7 @@ check_fields(Fs, Name, Fields, Vt, St0, CheckFun) ->
check_field({record_field,Lf,{atom,La,F},Val}, Name, Fields,
Vt, St, Sfs, CheckFun) ->
case member(F, Sfs) of
- true -> {Sfs,{Vt,add_error(Lf, {redefine_field,Name,F}, St)}};
+ true -> {Sfs,{[],add_error(Lf, {redefine_field,Name,F}, St)}};
false ->
{[F|Sfs],
case find_field(F, Fields) of
diff --git a/lib/stdlib/test/erl_lint_SUITE.erl b/lib/stdlib/test/erl_lint_SUITE.erl
index a1a9839bae..48ddeac478 100644
--- a/lib/stdlib/test/erl_lint_SUITE.erl
+++ b/lib/stdlib/test/erl_lint_SUITE.erl
@@ -560,7 +560,15 @@ unused_vars_warn_rec(Config) when is_list(Config) ->
{warnings,[{2,erl_lint,{unused_var,'X'}},
{3,erl_lint,{unused_var,'X'}},
{5,erl_lint,{unused_var,'X'}},
- {7,erl_lint,{unused_var,'X'}}]}}],
+ {7,erl_lint,{unused_var,'X'}}]}},
+ {rec3,
+ <<"-record(r, {a}).
+ t() -> X = 1, #r{a=foo, a=bar, a=qux}.
+ ">>,
+ [warn_unused_vars],
+ {error,[{2,erl_lint,{redefine_field,r,a}},
+ {2,erl_lint,{redefine_field,r,a}}],
+ [{2,erl_lint,{unused_var,'X'}}]}}],
?line [] = run(Config, Ts),
ok.