Skip to content

Commit e408364

Browse files
committed
Emit leaner code on =
1 parent ce17aa9 commit e408364

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

lib/elixir/src/elixir_clauses.erl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,16 @@ with(Meta, Args, S, E) ->
169169

170170
{{with, Meta, EExprs ++ [[{do, EDo} | EOpts]]}, S3, E}.
171171

172-
expand_with({'<-', Meta, [Left, Right]}, {S, E, _HasMatch}) ->
172+
expand_with({'<-', Meta, [Left, Right]}, {S, E, HasMatch}) ->
173173
{ERight, SR, ER} = elixir_expand:expand(Right, S, E),
174174
SM = elixir_env:reset_read(SR, S),
175175
{[ELeft], SL, EL} = head([Left], SM, ER),
176-
{{'<-', Meta, [ELeft, ERight]}, {SL, EL, true}};
176+
case ELeft of
177+
{Var, _, Ctx} when is_atom(Var), is_atom(Ctx) ->
178+
{{'=', Meta, [ELeft, ERight]}, {SL, EL, HasMatch}};
179+
_ ->
180+
{{'<-', Meta, [ELeft, ERight]}, {SL, EL, true}}
181+
end;
177182
expand_with(Expr, {S, E, HasMatch}) ->
178183
{EExpr, SE, EE} = elixir_expand:expand(Expr, S, E),
179184
{EExpr, {SE, EE, HasMatch}}.

lib/elixir/test/elixir/kernel/expansion_test.exs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,7 @@ defmodule Kernel.ExpansionTest do
10091009
after_expansion =
10101010
quote do
10111011
with(
1012-
b <-
1012+
b =
10131013
(
10141014
a = 1
10151015
2
@@ -1042,12 +1042,12 @@ defmodule Kernel.ExpansionTest do
10421042
after_expansion =
10431043
quote do
10441044
with(
1045-
b <-
1045+
b =
10461046
(
10471047
a = 1
10481048
2
10491049
),
1050-
d <-
1050+
d =
10511051
(
10521052
c = 3
10531053
4

0 commit comments

Comments
 (0)