File 0660-Fix-crash-when-compiling-binary-comprehensions.patch of Package erlang

From fd5c39100754832e4d4cf478a3e597e795772c32 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= <bjorn@erlang.org>
Date: Tue, 1 Dec 2020 15:28:52 +0100
Subject: [PATCH] Fix crash when compiling binary comprehensions

Fix a bug that would cause the compiler to crash when compiling
a binary comprehension where one generator depended on another
generator. Example:

    << <<X>> || L <- [[1]], X <- L >>

https://bugs.erlang.org/browse/ERL-1427
---
 lib/compiler/src/v3_core.erl           | 13 +++++++++++--
 lib/compiler/test/bs_bincomp_SUITE.erl | 19 +++++++++++--------
 2 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/lib/compiler/src/v3_core.erl b/lib/compiler/src/v3_core.erl
index d318fab15c..2be6568977 100644
--- a/lib/compiler/src/v3_core.erl
+++ b/lib/compiler/src/v3_core.erl
@@ -1717,8 +1717,17 @@ bc_add_list_1([H|T], Pre, E, St0) ->
 bc_add_list_1([], Pre, E, St) ->
     {E,reverse(Pre),St}.
 
-bc_gen_size(Q, EVs, St) ->
-    bc_gen_size_1(Q, EVs, #c_literal{val=1}, [], St).
+bc_gen_size([_]=Q, EVs, St) ->
+    %% Single generator.
+    bc_gen_size_1(Q, EVs, #c_literal{val=1}, [], St);
+bc_gen_size(_, _, _) ->
+    %% There are multiple generators (or there are filters).
+    %% To avoid introducing unbound variables in the size
+    %% calculation when one generator references a
+    %% variable bound by a previous generator, we will
+    %% not do any size calculation. This issue will be
+    %% handled in a cleaner way in OTP 24.
+    throw(impossible).
 
 bc_gen_size_1([{generate,L,El,Gen}|Qs], EVs, E0, Pre0, St0) ->
     bc_verify_non_filtering(El, EVs),
-- 
2.26.2

openSUSE Build Service is sponsored by