Skip to content

Commit 0f6c9d1

Browse files
committed
Make sure variables are not leaking from with
Closes #4123.
1 parent 0751f4b commit 0f6c9d1

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

lib/elixir/src/elixir_with.erl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ expand(X, E) ->
4444
translate(_Meta, Args, S) ->
4545
{Parts, [{do, Expr} | _Opts]} = elixir_utils:split_last(Args),
4646
Cases = build_cases(Parts, Expr),
47-
elixir_translator:translate(Cases, S).
47+
{TC, TS} = elixir_translator:translate(Cases, S),
48+
{TC, elixir_scope:mergec(S, TS)}.
4849

4950
build_cases([{'<-', Meta, [Left, Right]} | Rest], DoExpr) ->
5051
Other = {'other', Meta, nil},

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,9 @@ defmodule Kernel.ExpansionTest do
264264
test "variables inside with do not leak" do
265265
assert expand(quote do: (with(a <- b, do: c = 1); c)) ==
266266
quote do: (with(a <- b(), do: c = 1); c())
267+
268+
assert expand(quote do: (with(a = b, do: a); a)) ==
269+
quote do: (with(a = b(), do: a); a())
267270
end
268271

269272
test "variables inside with are available in blocks" do

0 commit comments

Comments
 (0)