From 4f0a99e57d213e84e8be4b826cecf04840754ed0 Mon Sep 17 00:00:00 2001 From: Alex Gubarev Date: Mon, 7 Sep 2026 01:09:37 +0300 Subject: [PATCH] Fix IEx.h/1 macro spec introspection --- lib/iex/lib/iex/introspection.ex | 7 ++++++- lib/iex/test/iex/helpers_test.exs | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/iex/lib/iex/introspection.ex b/lib/iex/lib/iex/introspection.ex index 7e59bbccef6..2e75454fb02 100644 --- a/lib/iex/lib/iex/introspection.ex +++ b/lib/iex/lib/iex/introspection.ex @@ -610,10 +610,15 @@ defmodule IEx.Introspection do end defp get_spec(module, name, arity) do + macro? = macro_exported?(module, name, arity) + name_arity = if macro?, do: {:elixir_utils.macro_name(name), arity + 1}, else: {name, arity} + with {:ok, all_specs} <- Typespec.fetch_specs(module), - {_, specs} <- List.keyfind(all_specs, {name, arity}, 0) do + {_, specs} <- List.keyfind(all_specs, name_arity, 0) do formatted = Enum.map(specs, fn spec -> + spec = if macro?, do: unpack_caller(spec), else: spec + Typespec.spec_to_quoted(name, spec) |> format_typespec(:spec, 2) end) diff --git a/lib/iex/test/iex/helpers_test.exs b/lib/iex/test/iex/helpers_test.exs index 57b462275eb..07d52a2178f 100644 --- a/lib/iex/test/iex/helpers_test.exs +++ b/lib/iex/test/iex/helpers_test.exs @@ -516,6 +516,13 @@ defmodule IEx.HelpersTest do assert capture_io(fn -> h(IEx.Helpers.recompile() / 1) end) =~ spec end + test "prints spec for default arg macro" do + spec = "@spec compile_env(app(), key() | list(), value()) :: value()" + + assert capture_io(fn -> h(Application.compile_env() / 2) end) =~ spec + assert capture_io(fn -> h(Application.compile_env() / 3) end) =~ spec + end + test "prints sigil documentation" do assert capture_io(fn -> h(~w//) end) =~ "Handles the sigil `~w` for list of words" end