Skip to content

Commit 65a3434

Browse files
author
José Valim
committed
Do not support Macro.var/1
1 parent 4ff9f9a commit 65a3434

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/elixir/lib/macro.ex

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,25 @@ defmodule Macro do
112112
@doc """
113113
Genrates a AST node representing the variable given
114114
by the atoms `var` and `context`.
115+
116+
## Examples
117+
118+
In order to build a variable, a context is expected.
119+
Most of the times, in order to preserve hygiene, the
120+
context must be `__MODULE__`:
121+
122+
iex> Macro.var(:foo, __MODULE__)
123+
{:foo, [], __MODULE__}
124+
125+
However, if there is a need to access the user variable,
126+
nil can be given:
127+
128+
iex> Macro.var(:foo, nil)
129+
{:foo, [], nil}
130+
115131
"""
116132
@spec var(var, context) :: {var, [], context} when var: atom, context: atom
117-
def var(var, context \\ nil) when is_atom(var) and is_atom(context) do
133+
def var(var, context) when is_atom(var) and is_atom(context) do
118134
{var, [], context}
119135
end
120136

lib/elixir/test/elixir/macro_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ defmodule MacroTest do
233233
end
234234

235235
test :var do
236-
assert Macro.var(:foo) == {:foo, [], nil}
236+
assert Macro.var(:foo, nil) == {:foo, [], nil}
237237
assert Macro.var(:foo, Other) == {:foo, [], Other}
238238
end
239239

0 commit comments

Comments
 (0)