From 7e0960b37ed0fc0d7cf721837359d0cd7a5b3099 Mon Sep 17 00:00:00 2001 From: Andrea Leopardi Date: Sat, 22 Sep 2018 22:29:48 +0200 Subject: [PATCH] Fix the t/1 IEx helper for private types (#8218) Closes #8208. --- lib/iex/lib/iex/introspection.ex | 15 +++++++++++---- lib/iex/test/iex/helpers_test.exs | 24 +++++++++++++++++++++++- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/lib/iex/lib/iex/introspection.ex b/lib/iex/lib/iex/introspection.ex index e8a92f3c734..6630f364178 100644 --- a/lib/iex/lib/iex/introspection.ex +++ b/lib/iex/lib/iex/introspection.ex @@ -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 @@ -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 @@ -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. diff --git a/lib/iex/test/iex/helpers_test.exs b/lib/iex/test/iex/helpers_test.exs index c54db41a1ca..8c8bcc56f3b 100644 --- a/lib/iex/test/iex/helpers_test.exs +++ b/lib/iex/test/iex/helpers_test.exs @@ -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