Skip to content

Commit 4d30464

Browse files
committed
Avoid conflicts between internal vars and empty vars, closes #15246
1 parent 139da8f commit 4d30464

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

lib/elixir/src/elixir_erl_var.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ build(Key, #elixir_erl{counter=Counter} = S) ->
4545
{build_name(Key, Count),
4646
S#elixir_erl{counter=Counter#{Key => Count}}}.
4747

48-
build_name('_', Count) -> list_to_atom("_@" ++ integer_to_list(Count));
48+
build_name('_', Count) -> list_to_atom("_" ++ integer_to_list(Count));
4949
build_name(Name, Count) -> list_to_atom("_" ++ atom_to_list(Name) ++ "@" ++ integer_to_list(Count)).
5050

5151
%% BINDINGS

lib/elixir/test/elixir/kernel/macros_test.exs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@ defmodule Kernel.MacrosTest.Nested do
1616
require Integer
1717
end
1818
end
19+
20+
defmacro wrap_empty_var(expr) do
21+
empty = Macro.var(:"", nil)
22+
23+
quote do
24+
(fn x ->
25+
unquote(empty) = List.wrap(x)
26+
unquote(empty)
27+
end).(unquote(expr))
28+
end
29+
end
1930
end
2031

2132
defmodule Kernel.MacrosTest do
@@ -91,4 +102,9 @@ defmodule Kernel.MacrosTest do
91102
1
92103
end) == 1
93104
end
105+
106+
test "do not collide on empty variable name", config do
107+
import Kernel.MacrosTest.Nested
108+
assert wrap_empty_var(config) == [config]
109+
end
94110
end

0 commit comments

Comments
 (0)