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
24 changes: 18 additions & 6 deletions lib/iex/lib/iex/introspection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -565,9 +565,9 @@ defmodule IEx.Introspection do
end
end

defp translate_callback({{name, arity}, specs}) do
case Atom.to_string(name) do
"MACRO-" <> macro_name ->
defp translate_callback({name_arity, specs}) do
case translate_callback_name_arity(name_arity) do
{:macrocallback, _, _} = kind_name_arity ->
# The typespec of a macrocallback differs from the one expressed
# via @macrocallback:
#
Expand All @@ -580,10 +580,17 @@ defmodule IEx.Introspection do
{:type, line1, :fun, [{:type, line2, :product, args}, spec]}
end)

{{:macrocallback, String.to_atom(macro_name), arity - 1}, specs}
{kind_name_arity, specs}

_ ->
{{:callback, name, arity}, specs}
kind_name_arity ->
{kind_name_arity, specs}
end
end

defp translate_callback_name_arity({name, arity}) do
case Atom.to_string(name) do
"MACRO-" <> macro_name -> {:macrocallback, String.to_atom(macro_name), arity - 1}
_ -> {:callback, name, arity}
end
end

Expand All @@ -599,6 +606,11 @@ defmodule IEx.Introspection do
optional_callbacks =
if Code.ensure_loaded?(mod) and function_exported?(mod, :behaviour_info, 1) do
mod.behaviour_info(:optional_callbacks)
|> Enum.map(fn name_arity ->
{_kind, name, arity} = translate_callback_name_arity(name_arity)
{name, arity}
end)
|> Enum.sort()
else
[]
end
Expand Down
11 changes: 7 additions & 4 deletions lib/iex/test/iex/helpers_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -725,18 +725,21 @@ defmodule IEx.HelpersTest do
content = """
defmodule OptionalCallbacks do
@doc "callback"
@callback optional_1(:foo) :: integer
@optional_callbacks optional_1: 1
@callback optional_callback(:foo) :: integer
@macrocallback optional_macrocallback(:bar) :: atom
@optional_callbacks optional_callback: 1, optional_macrocallback: 1
end
"""

with_file(filename, content, fn ->
assert c(filename, ".") == [OptionalCallbacks]

assert capture_io(fn -> b(OptionalCallbacks) end) =~ """
@callback optional_1(:foo) :: integer()
@callback optional_callback(:foo) :: integer()

@optional_callbacks [optional_1: 1]
@macrocallback optional_macrocallback(:bar) :: atom()

@optional_callbacks [optional_callback: 1, optional_macrocallback: 1]

"""
end)
Expand Down