summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Högberg <john@erlang.org>2019-09-19 10:30:59 +0200
committerJohn Högberg <john@erlang.org>2019-09-19 10:30:59 +0200
commita8afcc355620458d0cf08044309f937b653a4d82 (patch)
tree378eb3e25fc07c7eec3f041e0ed22eb35885bf1f
parent8c2badd69e163f7b4261dce242344f7f7af213b3 (diff)
parent2b856f88e16c852198c94c3df99c482927b08671 (diff)
downloaderlang-a8afcc355620458d0cf08044309f937b653a4d82.tar.gz
Merge branch 'maint'
* maint: erl_lint: Stop returning unsafe variables from comprehensions
-rw-r--r--lib/stdlib/src/erl_lint.erl8
-rw-r--r--lib/stdlib/test/erl_lint_SUITE.erl22
2 files changed, 26 insertions, 4 deletions
diff --git a/lib/stdlib/src/erl_lint.erl b/lib/stdlib/src/erl_lint.erl
index 0cd0aef124..d6cb57e392 100644
--- a/lib/stdlib/src/erl_lint.erl
+++ b/lib/stdlib/src/erl_lint.erl
@@ -3371,9 +3371,11 @@ handle_comprehension(E, Qs, Vt0, St0) ->
Vt3 = vtmerge(vtsubtract(Vt2, Uvt), Uvt),
%% Don't export local variables.
Vt4 = vtold(Vt3, Vt0),
- %% Forget about old variables which were not used.
- Vt5 = vt_no_unused(Vt4),
- {Vt5,St}.
+ %% Forget about old variables which were not used as well as unsafe
+ %% variables, preventing them from being marked as used and bound by
+ %% icrt_export/4.
+ Vt = vt_no_unsafe(vt_no_unused(Vt4)),
+ {Vt, St}.
%% lc_quals(Qualifiers, ImportVarTable, State) ->
%% {VarTable,ShadowedVarTable,State}
diff --git a/lib/stdlib/test/erl_lint_SUITE.erl b/lib/stdlib/test/erl_lint_SUITE.erl
index e7882e0daf..a8ed4b19db 100644
--- a/lib/stdlib/test/erl_lint_SUITE.erl
+++ b/lib/stdlib/test/erl_lint_SUITE.erl
@@ -1018,7 +1018,27 @@ unsafe_vars(Config) when is_list(Config) ->
{errors,[{24,erl_lint,{unsafe_var,'A',{'catch',4}}},
{24,erl_lint,{unsafe_var,'B',{'case',2}}},
{24,erl_lint,{unsafe_var,'D',{'case',2}}}],
- []}}
+ []}},
+ {unsafe_comprehension,
+ <<"foo() ->
+ case node() of
+ P when is_tuple(P) ->
+ P;
+ _ ->
+ ok
+ end,
+ Y = try
+ ok
+ catch _C:_R ->
+ [1 || _ <- []]
+ end,
+ case Y of
+ P ->
+ P
+ end.
+ ">>,
+ [],
+ {errors,[{14,erl_lint,{unsafe_var,'P',{'case',2}}}],[]}}
],
[] = run(Config, Ts),
ok.