diff --git a/lib/elixir/lib/kernel/typespec.ex b/lib/elixir/lib/kernel/typespec.ex index 485a367b12..1f3539bcf9 100644 --- a/lib/elixir/lib/kernel/typespec.ex +++ b/lib/elixir/lib/kernel/typespec.ex @@ -877,7 +877,15 @@ defmodule Kernel.Typespec do defp typespec({:fun, meta, args}, vars, caller, state) do {args, state} = :lists.mapfoldl(&typespec(&1, vars, caller, &2), state, args) - {{:type, location(meta), :fun, args}, state} + + if args != [] do + IO.warn( + "fun/#{length(args)} is not valid in typespecs. Either specify fun() or use (... -> return) instead", + caller + ) + end + + {{:type, location(meta), :fun, []}, state} end defp typespec({:..., _meta, _args}, _vars, caller, _state) do diff --git a/lib/elixir/test/elixir/kernel/warning_test.exs b/lib/elixir/test/elixir/kernel/warning_test.exs index f118456f9d..eb0dd65930 100644 --- a/lib/elixir/test/elixir/kernel/warning_test.exs +++ b/lib/elixir/test/elixir/kernel/warning_test.exs @@ -1818,6 +1818,20 @@ defmodule Kernel.WarningTest do purge([Sample1, Sample2, Sample3]) end + test "invalid fun" do + assert_warn_eval( + [ + "nofile:2: ", + "fun/1 is not valid in typespecs. Either specify fun() or use (... -> return) instead" + ], + """ + defmodule InvalidFunType do + @type my_type :: fun(integer()) + end + """ + ) + end + test "invalid type annotations" do assert_warn_eval( [