[erlang-questions] Dialyzer cannot catch gen_server callback return type error

Motiejus Jakštys <>
Thu Jul 5 13:17:48 CEST 2012


On Thu, Jul 05, 2012 at 04:12:01PM +0700, Maxim Treskin wrote:
> Hello
> 
> I got error when gen_server callback returns not a proper process state,
> but another erlang term(), and dialyzer not warns me about this.
> After specification of Module:handle_cast/2 with
> 
> -spec handle_cast(Msg :: term(), State :: #state{}) -> {noreply, NewState
> :: #state{}}.
> 
> where #state{} is record of process state,

I don't know about this one,

> it not warns too (it also not warns about {stop, normal, State} return
> value).

but this is fine. Your function returns a *subtype* of what
Mod:handle_cast/2 is supposed to return.

If you added something that is not in return values of handle_cast, like
this:

-spec handle_cast(term(), #state{}) -> {noreply, NewState} | wrong.

Dialyzer will warn you that gen_server is not expecting 'wrong'.

> Code of callback:
> 
> handle_cast({message}, _State) ->
>     NewState = {bugotak},
>     {noreply, NewState};
> 
> Is it possible to make that dialyzer can see this mistake? Does it check
> types of gen_server callbacks?

But this one would be interesting indeed.

Motiejus



More information about the erlang-questions mailing list