Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/elixir/src/elixir_erl_pass.erl
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,9 @@ build_truthy_clause(Meta, Condition, Body, S) ->
%% In case a variable is defined to match in a condition
%% but a condition returns boolean, we can replace the
%% variable directly by the boolean result.
returns_boolean({'=', _, [{Var, _, Ctx}, Condition]}, {Var, _, Ctx}) when is_atom(Var), is_atom(Ctx) ->
case elixir_utils:returns_boolean(Condition) of
returns_boolean({'=', _, [{Var, VarMeta, Ctx}, Condition]}, {Var, BodyMeta, Ctx}) when is_atom(Var), is_atom(Ctx) ->
case elixir_utils:returns_boolean(Condition) andalso
lists:keyfind(version, 1, VarMeta) =:= lists:keyfind(version, 1, BodyMeta) of
true -> {Condition, true};
false -> false
end;
Expand Down
19 changes: 19 additions & 0 deletions lib/elixir/test/elixir/kernel/macros_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@ defmodule Kernel.MacrosTest.Nested do
end
end

defmacro outer_cond do
quote do
x = :outer_value
Kernel.MacrosTest.Nested.inner_cond(x)
end
end

defmacro inner_cond(body) do
quote do
cond do
x = is_integer(1) -> unquote(body)
end
end
end

defmacro wrap_empty_var(expr) do
empty = Macro.var(:"", nil)

Expand Down Expand Up @@ -76,6 +91,10 @@ defmodule Kernel.MacrosTest do
assert Nested.value() == 1
end

test "cond preserves hygienically distinct variables in the body" do
assert Nested.outer_cond() == :outer_value
end

test "local with private macro" do
assert my_private_macro() == 4
end
Expand Down
Loading