File 0177-Fix-infinite-loop-in-shell-caused-by-record-with-rec.patch of Package erlang

From 83eda421d5da52328f5c5f552967591e22a0695e Mon Sep 17 00:00:00 2001
From: Svilen Ivanov <isvilen@applicata.bg>
Date: Sat, 17 Jun 2017 15:16:50 +0300
Subject: [PATCH 1/2] Fix infinite loop in shell caused by record with
 recursive typespec

If record with recursive typespec such as

  -record(r,{f :: #r{} | undefined}).

is used in interactive shell it stucks in inifinite loop when
trying to find definitions for all records used in expression.
---
 lib/stdlib/src/shell.erl | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/lib/stdlib/src/shell.erl b/lib/stdlib/src/shell.erl
index 6eafc7b20..26b3960f4 100644
--- a/lib/stdlib/src/shell.erl
+++ b/lib/stdlib/src/shell.erl
@@ -727,7 +727,7 @@ result_will_be_saved() ->
 used_record_defs(E, RT) ->
     %% Be careful to return a list where used records come before
     %% records that use them. The linter wants them ordered that way.
-    UR = case used_records(E, [], RT) of
+    UR = case used_records(E, [], RT, []) of
              [] -> 
                  [];
              L0 ->
@@ -737,13 +737,19 @@ used_record_defs(E, RT) ->
          end,
     record_defs(RT, UR).
 
-used_records(E, U0, RT) ->
+used_records(E, U0, RT, Skip) ->
     case used_records(E) of
         {name,Name,E1} ->
-            U = used_records(ets:lookup(RT, Name), [Name | U0], RT),
-            used_records(E1, U, RT);
+            U = case lists:member(Name, Skip) of
+                    true ->
+                        U0;
+                    false ->
+                        R = ets:lookup(RT, Name),
+                        used_records(R, [Name | U0], RT, [Name | Skip])
+                end,
+            used_records(E1, U, RT, Skip);
         {expr,[E1 | Es]} ->
-            used_records(Es, used_records(E1, U0, RT), RT);
+            used_records(Es, used_records(E1, U0, RT, Skip), RT, Skip);
         _ ->
             U0
     end.
-- 
2.13.2

openSUSE Build Service is sponsored by