File 0767-erl_lint-Stop-returning-unsafe-variables-from-compre.patch of Package erlang

From 84192f0a40bb55f4b0c7b74081b2569fea5bb472 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?John=20H=C3=B6gberg?= <john@erlang.org>
Date: Tue, 10 Sep 2019 11:30:36 +0200
Subject: [PATCH] erl_lint: Stop returning unsafe variables from comprehensions

This prevents unsafe variables from being indirectly marked as used
and bound.
---
 lib/stdlib/src/erl_lint.erl        |  8 +++++---
 lib/stdlib/test/erl_lint_SUITE.erl | 22 +++++++++++++++++++++-
 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.
-- 
2.16.4

openSUSE Build Service is sponsored by