[erlang-questions] 12B4 dialyzer problem 2

Anthony Shipman <>
Thu Sep 11 11:56:03 CEST 2008


I have a gen_server with a state record specified as:

-record(state, {
    parent	:: pid(),
    strmID	:: integer(),
   ....
   }).

-type state()  :: #state{}.

It is initialised in my init() function like:

    State = #state{
	parent        = Parent,
	strmID	   = StrmID,
        ....
        }

and then threaded through the handle_* functions which reaches this code:

cancelCall(State) ->
    streamIface:specialToDevice(State#state.parent,
                 State#state.strmID, streamClose),

 I get this error from dialyzer:

stream_reman.erl:576: The call streamIface:specialToDevice('undefined' | 
pid(),'undefined' | integer(),'streamClose')
 breaks the contract (serverRef(),integer(),specialCtrl()) -> 'ok'

It appears that dialyzer can't prove that the parent and strmID fields can 
never be undefined. This isn't surprising. But I expected that dialyzer would 
accept the declaration
	parent:: pid(),
to tell it that the field is never undefined.

If I am going to get this problem everywhere I use this basic gen_server idiom 
then dialyzer is going to give me lots and lots of false negatives.

-- 
Anthony Shipman                    Mamas don't let your babies 
                   grow up to be outsourced.



More information about the erlang-questions mailing list