From 94ee934039d9434cea155ed55603d0a8fe62effe Mon Sep 17 00:00:00 2001 From: Alex Gubarev Date: Tue, 28 Jul 2026 12:44:41 +0300 Subject: [PATCH] Fix IEx.Helpers.h print spec for default arg function --- lib/iex/lib/iex/introspection.ex | 21 +++++++++++++++++++-- lib/iex/test/iex/helpers_test.exs | 7 +++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/iex/lib/iex/introspection.ex b/lib/iex/lib/iex/introspection.ex index 31f412bd20d..7e59bbccef6 100644 --- a/lib/iex/lib/iex/introspection.ex +++ b/lib/iex/lib/iex/introspection.ex @@ -465,10 +465,11 @@ defmodule IEx.Introspection do defp h_mod_fun_arity(mod, fun, arity) when is_atom(mod) do {language, format, docs} = get_docs(mod, [:function, :macro]) - spec = get_spec(mod, fun, arity) + doc_tuple = find_doc_with_content(docs, fun, arity) + spec = get_spec(mod, fun, arity, doc_tuple) cond do - doc_tuple = find_doc_with_content(docs, fun, arity) -> + doc_tuple -> print_fun(mod, language, format, doc_tuple, spec) :ok @@ -592,6 +593,22 @@ defmodule IEx.Introspection do |> Enum.find(&has_callback?(&1, fun, arity)) end + defp get_spec(module, name, arity, doc_tuple) do + case get_spec(module, name, arity) do + [] -> + case doc_tuple do + {{_, ^name, doc_arity}, _, _, _, _} when doc_arity != arity -> + get_spec(module, name, doc_arity) + + _ -> + [] + end + + spec -> + spec + end + end + defp get_spec(module, name, arity) do with {:ok, all_specs} <- Typespec.fetch_specs(module), {_, specs} <- List.keyfind(all_specs, {name, arity}, 0) do diff --git a/lib/iex/test/iex/helpers_test.exs b/lib/iex/test/iex/helpers_test.exs index f2433c7925f..32628ebc291 100644 --- a/lib/iex/test/iex/helpers_test.exs +++ b/lib/iex/test/iex/helpers_test.exs @@ -515,6 +515,13 @@ defmodule IEx.HelpersTest do assert capture_io(fn -> h(def) end) =~ def_h end + test "prints spec for default arg function" do + spec = "@spec recompile([{:force, boolean()}]) :: :ok | :error | :noop" + + assert capture_io(fn -> h(IEx.Helpers.recompile() / 0) end) =~ spec + assert capture_io(fn -> h(IEx.Helpers.recompile() / 1) end) =~ spec + end + test "prints sigil documentation" do assert capture_io(fn -> h(~w//) end) =~ "Handles the sigil `~w` for list of words" end