diff --git a/lib/elixir/lib/protocol.ex b/lib/elixir/lib/protocol.ex index c1e1f74adb..ba8ab3c3c5 100644 --- a/lib/elixir/lib/protocol.ex +++ b/lib/elixir/lib/protocol.ex @@ -723,6 +723,13 @@ defmodule Protocol do {name, length(args)} end + defp callback_ast_to_fa( + {kind, {:when, _, [{:"::", _, [{name, _, args}, _return]}, _vars]}, _pos} + ) + when kind in [:callback, :macrocallback] do + {name, length(args)} + end + defp warn(message, env) do IO.warn(message, Macro.Env.stacktrace(env)) end diff --git a/lib/elixir/test/elixir/kernel/warning_test.exs b/lib/elixir/test/elixir/kernel/warning_test.exs index 82dcfd09e7..1a2251b2f9 100644 --- a/lib/elixir/test/elixir/kernel/warning_test.exs +++ b/lib/elixir/test/elixir/kernel/warning_test.exs @@ -1158,11 +1158,17 @@ defmodule Kernel.WarningTest do @spec with_specs(any(), keyword()) :: tuple() def with_specs(term, options \\ []) + @spec with_specs_and_when(any(), opts) :: tuple() when opts: keyword + def with_specs_and_when(term, options \\ []) + def without_specs(term, options \\ []) @callback foo(term) :: {:ok, term} @callback foo(term, keyword) :: {:ok, term, keyword} + @callback foo_when(x) :: {:ok, x} when x: term + @callback foo_when(x, opts) :: {:ok, x, opts} when x: term, opts: keyword + @macrocallback bar(term) :: {:ok, term} @macrocallback bar(term, keyword) :: {:ok, term, keyword} @@ -1178,6 +1184,12 @@ defmodule Kernel.WarningTest do assert message =~ "cannot define @callback foo/2 inside protocol, use def/1 to outline your protocol definition\n nofile:1" + assert message =~ + "cannot define @callback foo_when/1 inside protocol, use def/1 to outline your protocol definition\n nofile:1" + + assert message =~ + "cannot define @callback foo_when/2 inside protocol, use def/1 to outline your protocol definition\n nofile:1" + assert message =~ "cannot define @macrocallback bar/1 inside protocol, use def/1 to outline your protocol definition\n nofile:1"