I’ve just started putting dialyzer into my project in conjunction with writing behaviours for the call back modules.
Up until this point the callbacks that need implementing have only been defined in the documentation.
In my Ace.TCP.Server
module I have the following types and callbacks specified.
defmodule Ace.TCP.server do
@type connection :: %{peer: term}
@type state :: term
@callback init(connection, state) ::
{:send, term, state} |
{:send, term, state, timeout} |
{:nosend, state} |
{:nosend, state, timeout}
@callback handle_packet(any, state) ::
{:send, term, state} |
{:send, term, state, timeout} |
{:nosend, state} |
{:nosend, state, timeout}
end
# The rest of the functionality
I have a Forwarder
module that uses this behaviour. Forwarder is part of my test suite.
defmodule Forwarder do
@behaviour Ace.TCP.Server
def init(conn, pid) do
send(pid, {:conn, conn})
{:nosend, pid}
end
def handle_packet(_p, _s) do
end
end
When handle_packet/2
is missing I get a warning when running my tests. yet when it is present as above. I.e. returning nil
I get no error from dialyzer. So my question is why is dialyzer missing that this callback doesn’t implement the correct types?