Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Do not export variables from comprehension cases in v3_core #269

Closed
wants to merge 1 commit into from

4 participants

@nox
nox commented

Code like the following snippet could make the compiler crash:

f() -> [X = a || false] ++ [X = a || false].

@UlfNorell

@bjorng
Collaborator

Have you tested this code?

The logic of your correction seems to be backwards. You don't export any variables from a case except when it is a list comprehension.

Also, the compiler crashes when I attempt to build a new primary bootstrap or test suites.

@nox
nox commented

Oh right, fixed something at the last moment and flipped the condition.

@nox nox Do not export variables from comprehension cases in v3_core
Code like the following snippet could make the compiler crash:

    f() -> [X = a || false] ++ [X = a || false].

Reported-by: Ulf Norell
96bf149
@nox
nox commented

Fixed and checked that the primary bootstrap can be built.

@bjorng
Collaborator

Looks good except that the lists: prefix should not be used in the compiler source code. I have fixed that and included the branch in our daily builds.

@nox
nox commented

There are others list calls in the module, that's why I didn't import it.

@bjorng
Collaborator

Yes, I will talk to Björn-Egil about those other lists calls. :-)

There is no need import lists:member/2, since it is already imported.

@psyeugenic
Owner

Kick him when he is down! =)

@OTP-Maintainer

Patch has passed first testings and has been assigned to be reviewed

@bjorng
Collaborator

Merged.

@bjorng bjorng closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 5, 2014
  1. @nox

    Do not export variables from comprehension cases in v3_core

    nox authored
    Code like the following snippet could make the compiler crash:
    
        f() -> [X = a || false] ++ [X = a || false].
    
    Reported-by: Ulf Norell
This page is out of date. Refresh to see the latest.
Showing with 11 additions and 4 deletions.
  1. +5 −2 lib/compiler/src/v3_core.erl
  2. +6 −2 lib/compiler/test/lc_SUITE.erl
View
7 lib/compiler/src/v3_core.erl
@@ -1765,13 +1765,16 @@ uexpr(#iletrec{anno=A,defs=Fs0,body=B0}, Ks, St0) ->
{B1,St2} = uexprs(B0, Ks, St1),
Used = used_in_any(map(fun ({_,F}) -> F end, Fs1) ++ B1),
{#iletrec{anno=A#a{us=Used,ns=[]},defs=Fs1,body=B1},St2};
-uexpr(#icase{anno=A,args=As0,clauses=Cs0,fc=Fc0}, Ks, St0) ->
+uexpr(#icase{anno=#a{anno=Anno}=A,args=As0,clauses=Cs0,fc=Fc0}, Ks, St0) ->
%% As0 will never generate new variables.
{As1,St1} = uexpr_list(As0, Ks, St0),
{Cs1,St2} = uclauses(Cs0, Ks, St1),
{Fc1,St3} = uclause(Fc0, Ks, St2),
Used = union(used_in_any(As1), used_in_any(Cs1)),
- New = new_in_all(Cs1),
+ New = case lists:member(list_comprehension, Anno) of
+ true -> [];
+ false -> new_in_all(Cs1)
+ end,
{#icase{anno=A#a{us=Used,ns=New},args=As1,clauses=Cs1,fc=Fc1},St3};
uexpr(#ifun{anno=A0,id=Id,vars=As,clauses=Cs0,fc=Fc0,name=Name}, Ks0, St0) ->
Avs = lit_list_vars(As),
View
8 lib/compiler/test/lc_SUITE.erl
@@ -23,7 +23,7 @@
init_per_group/2,end_per_group/2,
init_per_testcase/2,end_per_testcase/2,
basic/1,deeply_nested/1,no_generator/1,
- empty_generator/1]).
+ empty_generator/1,no_export/1]).
-include_lib("test_server/include/test_server.hrl").
@@ -31,7 +31,7 @@ suite() -> [{ct_hooks,[ts_install_cth]}].
all() ->
test_lib:recompile(?MODULE),
- [basic, deeply_nested, no_generator, empty_generator].
+ [basic, deeply_nested, no_generator, empty_generator, no_export].
groups() ->
[].
@@ -177,6 +177,10 @@ empty_generator(Config) when is_list(Config) ->
?line [] = [X || {X} <- [], (false or (X/0 > 3))],
ok.
+no_export(Config) when is_list(Config) ->
+ [] = [ _X = a || false ] ++ [ _X = a || false ],
+ ok.
+
id(I) -> I.
fc(Args, {'EXIT',{function_clause,[{?MODULE,_,Args,_}|_]}}) -> ok;
Something went wrong with that request. Please try again.