Skip to content

Commit

Permalink
Do not convert user types into types, closes #2086
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Jan 30, 2025
1 parent 6c184a8 commit 943036d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/ex_doc/language/source.ex
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ defmodule ExDoc.Language.Source do
end

defp expand_records({type, anno, what, args}, records) when type in [:type, :user_type] do
{:type, anno, what, expand_records(args, records)}
{type, anno, what, expand_records(args, records)}
end

defp expand_records({:remote_type, anno, [m, t, args]}, records) do
Expand Down
12 changes: 7 additions & 5 deletions test/ex_doc/retriever/erlang_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,12 @@ defmodule ExDoc.Retriever.ErlangTest do
d = 1,
e}).
-type type() :: #a{}.
% We explicitly name the type union because that's an internal type
% and we want to make sure we deal with conflicts properly.
-type union() :: #a{}.
-callback callback() -> #a{}.
-spec function() -> type() | #a{ a :: integer(), b :: integer() }.
-spec function() -> union() | #a{ a :: integer(), b :: integer() }.
function() -> ok.
""")

Expand All @@ -351,15 +353,15 @@ defmodule ExDoc.Retriever.ErlangTest do

assert hd(function.specs)
|> Erlang.autolink_spec(current_module: :mod, current_kfa: {:function, :function, 0}) ==
"function() -> <a href=\"#t:type/0\">type</a>() | #a{a :: <a href=\"https://www.erlang.org/doc/apps/erts/erlang.html#t:integer/0\">integer</a>(), b :: <a href=\"https://www.erlang.org/doc/apps/erts/erlang.html#t:integer/0\">integer</a>(), c :: <a href=\"https://www.erlang.org/doc/apps/erts/erlang.html#t:atom/0\">atom</a>(), d :: <a href=\"https://www.erlang.org/doc/apps/erts/erlang.html#t:term/0\">term</a>(), e :: <a href=\"https://www.erlang.org/doc/apps/erts/erlang.html#t:term/0\">term</a>()}."
"function() -> <a href=\"#t:union/0\">union</a>() | #a{a :: <a href=\"https://www.erlang.org/doc/apps/erts/erlang.html#t:integer/0\">integer</a>(), b :: <a href=\"https://www.erlang.org/doc/apps/erts/erlang.html#t:integer/0\">integer</a>(), c :: <a href=\"https://www.erlang.org/doc/apps/erts/erlang.html#t:atom/0\">atom</a>(), d :: <a href=\"https://www.erlang.org/doc/apps/erts/erlang.html#t:term/0\">term</a>(), e :: <a href=\"https://www.erlang.org/doc/apps/erts/erlang.html#t:term/0\">term</a>()}."

assert hd(callback.specs)
|> Erlang.autolink_spec(current_module: :mod, current_kfa: {:callback, :callback, 0}) ==
"callback() ->\n #a{a :: <a href=\"https://www.erlang.org/doc/apps/erts/erlang.html#t:pos_integer/0\">pos_integer</a>(), b :: <a href=\"https://www.erlang.org/doc/apps/erts/erlang.html#t:non_neg_integer/0\">non_neg_integer</a>(), c :: <a href=\"https://www.erlang.org/doc/apps/erts/erlang.html#t:atom/0\">atom</a>(), d :: <a href=\"https://www.erlang.org/doc/apps/erts/erlang.html#t:term/0\">term</a>(), e :: <a href=\"https://www.erlang.org/doc/apps/erts/erlang.html#t:term/0\">term</a>()}."

assert hd(type.specs)
|> Erlang.autolink_spec(current_module: :mod, current_kfa: {:type, :type, 0}) ==
"type() :: #a{a :: <a href=\"https://www.erlang.org/doc/apps/erts/erlang.html#t:pos_integer/0\">pos_integer</a>(), b :: <a href=\"https://www.erlang.org/doc/apps/erts/erlang.html#t:non_neg_integer/0\">non_neg_integer</a>(), c :: <a href=\"https://www.erlang.org/doc/apps/erts/erlang.html#t:atom/0\">atom</a>(), d :: <a href=\"https://www.erlang.org/doc/apps/erts/erlang.html#t:term/0\">term</a>(), e :: <a href=\"https://www.erlang.org/doc/apps/erts/erlang.html#t:term/0\">term</a>()}."
|> Erlang.autolink_spec(current_module: :mod, current_kfa: {:type, :union, 0}) ==
"union() :: #a{a :: <a href=\"https://www.erlang.org/doc/apps/erts/erlang.html#t:pos_integer/0\">pos_integer</a>(), b :: <a href=\"https://www.erlang.org/doc/apps/erts/erlang.html#t:non_neg_integer/0\">non_neg_integer</a>(), c :: <a href=\"https://www.erlang.org/doc/apps/erts/erlang.html#t:atom/0\">atom</a>(), d :: <a href=\"https://www.erlang.org/doc/apps/erts/erlang.html#t:term/0\">term</a>(), e :: <a href=\"https://www.erlang.org/doc/apps/erts/erlang.html#t:term/0\">term</a>()}."
end
end

Expand Down

0 comments on commit 943036d

Please sign in to comment.