Skip to content

Commit

Permalink
Fix the t/1 IEx helper for private types (elixir-lang#8218)
Browse files Browse the repository at this point in the history
  • Loading branch information
whatyouhide authored Sep 22, 2018
1 parent 80ce444 commit 7e0960b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
15 changes: 11 additions & 4 deletions lib/iex/lib/iex/introspection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -636,13 +636,14 @@ defmodule IEx.Introspection do

{:ok, types} ->
printed =
for {_, {^type, _, args}} = typespec <- types do
for {kind, {^type, _, args}} = typespec <- types,
kind != :typep do
type_doc(module, type, length(args), typespec)
|> print_typespec()
end

if printed == [] do
types_not_found("#{inspect(module)}.#{type}")
types_not_found_or_private("#{inspect(module)}.#{type}")
end
end

Expand All @@ -656,13 +657,15 @@ defmodule IEx.Introspection do

{:ok, types} ->
printed =
for {_, {^type, _, args}} = typespec <- types, length(args) == arity do
for {kind, {^type, _, args}} = typespec <- types,
kind != :typep,
length(args) == arity do
type_doc(module, type, arity, typespec)
|> print_typespec()
end

if printed == [] do
types_not_found("#{inspect(module)}.#{type}")
types_not_found_or_private("#{inspect(module)}.#{type}")
end
end

Expand Down Expand Up @@ -769,6 +772,10 @@ defmodule IEx.Introspection do
defp types_not_found(for), do: not_found(for, "type information")
defp docs_not_found(for), do: not_found(for, "documentation")

defp types_not_found_or_private(for) do
puts_error("No type information for #{for} was found or #{for} is private")
end

defp behaviour_found(for) do
puts_error("""
No documentation for function #{for} was found, but there is a callback with the same name.
Expand Down
24 changes: 23 additions & 1 deletion lib/iex/test/iex/helpers_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -671,8 +671,30 @@ defmodule IEx.HelpersTest do
end

describe "t" do
test "prints when there is no type information" do
test "prints when there is no type information or the type is private" do
assert capture_io(fn -> t(IEx) end) == "No type information for IEx was found\n"

assert capture_io(fn -> t(Enum.doesnt_exist()) end) ==
"No type information for Enum.doesnt_exist was found or " <>
"Enum.doesnt_exist is private\n"

contents = """
defmodule TypeSample do
@type public_so_t_doesnt_warn() :: t()
@typep t() :: term()
end
"""

filename = "typesample.ex"

with_file(filename, contents, fn ->
assert c(filename, ".") == [TypeSample]

assert capture_io(fn -> t(TypeSample.t() / 0) end) ==
"No type information for TypeSample.t was found or TypeSample.t is private\n"
end)
after
cleanup_modules([TypeSample])
end

test "prints all types in module" do
Expand Down

0 comments on commit 7e0960b

Please sign in to comment.