[erlang-questions] Dialyzer cannot catch gen_server callback return type error
Stavros Aronis
aronisstav@REDACTED
Fri Jul 6 12:35:28 CEST 2012
Hi again,
The signature (or "success typing" in Dialyzer's terminology) is
`my_module:handle_cast(term(),term()) -> {'noreply',term()}` because the
second clause:
handle_cast(_Msg, State) ->
{noreply, State}.
will accept any terms as _Msg and State and return {noreply, State} in
which State again is any term. In Dialyzer's type system, this {noreply,
term()} return value will 'absorb' the definitely incorrect {noreply,
{bugotak}} as {bugotak} is also a term(). From that point on, Dialyzer can
assume that term() might also be #state{} and emit no warnings. This
happens because Dialyzer checks the whole range of return values at once
and not each particular clause. If all the return values were definitely
different than #state{}, then and only then would Dialyzer warn you.
Again, trying to check each particular return value against a given spec
might be an interesting extension and we will consider it in the future.
Stavros
On Fri, Jul 6, 2012 at 11:39 AM, Maxim Treskin <zerthurd@REDACTED> wrote:
> I just really not understand. Function handle_cast returns, and returns
> incorrect type according to -spec signature, right?
> Why Dialyzer lose this information? It is sort of missbehaviour i think.
>
> --
> Max Treskin
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120706/8394ef5c/attachment.htm>
More information about the erlang-questions
mailing list