Skip to content

Commit 75fcdac

Browse files
committed
Check also Kernel.SpecialForms in h(). Fixes #906
1 parent 538a29e commit 75fcdac

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed

lib/iex/lib/iex/helpers.ex

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,17 @@ defmodule IEx.Helpers do
123123

124124
defmacro h({ name, _, args }) when args == [] or is_atom(args) do
125125
quote do
126-
h(unquote(__MODULE__), unquote(name))
127-
h(Kernel, unquote(name))
126+
candidates = [unquote(__MODULE__), Kernel, Kernel.SpecialForms]
127+
128+
# If we got at least one :ok, final result will be :ok
129+
Enum.reduce candidates, :not_found, fn(mod, flag) ->
130+
ret = h(mod, unquote(name))
131+
if flag == :ok do
132+
:ok
133+
else
134+
ret
135+
end
136+
end
128137
end
129138
end
130139

@@ -134,17 +143,31 @@ defmodule IEx.Helpers do
134143
end
135144
end
136145

146+
defmacrop mfa_exported?(module, function, arity) do
147+
quote do
148+
function_exported?(unquote(module), unquote(function), unquote(arity)) or
149+
macro_exported?(unquote(module), unquote(function), unquote(arity))
150+
end
151+
end
152+
153+
defp h_kernel(function, arity) do
154+
if mfa_exported?(Kernel, function, arity) do
155+
h(Kernel, function, arity)
156+
else
157+
h(Kernel.SpecialForms, function, arity)
158+
end
159+
end
160+
137161
@doc false
138162
def h(:h, 1) do
139163
h(__MODULE__, :h, 1)
140164
end
141165

142166
def h(function, arity) when is_atom(function) and is_integer(arity) do
143-
if function_exported?(__MODULE__, function, arity) or
144-
macro_exported?(__MODULE__, function, arity) do
167+
if mfa_exported?(__MODULE__, function, arity) do
145168
h(__MODULE__, function, arity)
146169
else
147-
h(Kernel, function, arity)
170+
h_kernel(function, arity)
148171
end
149172
end
150173

@@ -166,12 +189,16 @@ defmodule IEx.Helpers do
166189
end
167190

168191
def h(module, function) when is_atom(module) and is_atom(function) do
169-
lc {{f, arity}, _line, _type, _args, doc } inlist module.__info__(:docs),
192+
result = lc {{f, arity}, _line, _type, _args, doc } inlist module.__info__(:docs),
170193
f == function and doc != false do
171194
h(module, function, arity)
172195
IO.puts ""
173196
end
174-
:ok
197+
if length(result) > 0 do
198+
:ok
199+
else
200+
:not_found
201+
end
175202
end
176203

177204
def h(_, _) do

0 commit comments

Comments
 (0)