Skip to content

Commit 3f6dd0b

Browse files
authored
No longer wrap expression in binary as Erlang/OTP 20+ does it by default (#8530)
1 parent ec2e092 commit 3f6dd0b

File tree

1 file changed

+8
-19
lines changed

1 file changed

+8
-19
lines changed

lib/elixir/src/elixir_erl_for.erl

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,9 @@ translate(Meta, Args, Return, S) ->
1919
{TExpr, SE} = elixir_erl_pass:translate(wrap_expr(Expr, TInto), SC),
2020
SF = elixir_erl_var:mergec(SI, SE),
2121

22-
case comprehension_expr(TInto, TExpr) of
23-
{inline, TIntoExpr} ->
24-
build_inline(Ann, TCases, TIntoExpr, TInto, TUniq, SF);
25-
{into, TIntoExpr} ->
26-
build_into(Ann, TCases, TIntoExpr, TInto, TUniq, SF)
22+
case inline_or_into(TInto) of
23+
inline -> build_inline(Ann, TCases, TExpr, TInto, TUniq, SF);
24+
into -> build_into(Ann, TCases, TExpr, TInto, TUniq, SF)
2725
end.
2826

2927
%% In case we have no return, we wrap the expression
@@ -88,7 +86,6 @@ collect_filters([H | T], Acc) ->
8886
collect_filters([], Acc) ->
8987
{Acc, []}.
9088

91-
9289
build_inline(Ann, Clauses, Expr, Into, Uniq, S) ->
9390
case not Uniq and lists:all(fun(Clause) -> element(1, Clause) == bin end, Clauses) of
9491
true -> {build_comprehension(Ann, Clauses, Expr, Into), S};
@@ -294,8 +291,6 @@ no_var_expr(Ann, _) -> [{var, Ann, '_'}].
294291
no_var_size({var, _, _}) -> throw(unbound_size);
295292
no_var_size(Size) -> Size.
296293

297-
build_comprehension(Ann, Clauses, Expr, false) ->
298-
{lc, Ann, Expr, comprehension_clause(Clauses)};
299294
build_comprehension(Ann, Clauses, Expr, Into) ->
300295
{comprehension_kind(Into), Ann, Expr, comprehension_clause(Clauses)}.
301296

@@ -307,23 +302,17 @@ comprehension_clause([{Kind, Meta, Left, Right, Filters} | T]) ->
307302
comprehension_clause([]) ->
308303
[].
309304

305+
comprehension_kind(false) -> lc;
310306
comprehension_kind({nil, _}) -> lc;
311307
comprehension_kind({bin, _, []}) -> bc.
312308

313309
comprehension_generator(enum) -> generate;
314310
comprehension_generator(bin) -> b_generate.
315311

316-
comprehension_expr({bin, _, []}, {bin, _, _} = Expr) ->
317-
{inline, Expr};
318-
comprehension_expr({bin, Ann, []}, Expr) ->
319-
BinExpr = {bin, Ann, [{bin_element, Ann, Expr, default, [bitstring]}]},
320-
{inline, BinExpr};
321-
comprehension_expr({nil, _}, Expr) ->
322-
{inline, Expr};
323-
comprehension_expr(false, Expr) ->
324-
{inline, Expr};
325-
comprehension_expr(_, Expr) ->
326-
{into, Expr}.
312+
inline_or_into({bin, _, []}) -> inline;
313+
inline_or_into({nil, _}) -> inline;
314+
inline_or_into(false) -> inline;
315+
inline_or_into(_) -> into.
327316

328317
comprehension_filter(Ann, Filters) ->
329318
[join_filter(Ann, Filter, {atom, Ann, true}, {atom, Ann, false}) ||

0 commit comments

Comments
 (0)