[erlang-questions] Dialyzer warning

Kostis Sagonas kostis@REDACTED
Fri Sep 23 18:17:07 CEST 2011


On 09/23/11 18:34, Fernando "Brujo" Benavides wrote:
> Hi everybody,
>
> I have a question that's mainly for Kostis, but maybe there're other out
> there that had faced similar problems before.
> I run dialyzer against the binaries of this project
> <https://github.com/inaka/match_stream> as it's shown in its Makefile
> <https://github.com/inaka/match_stream/blob/master/Makefile> and I get:
>
>> match_stream_user_mgr.erl:32: The specification for
>> match_stream_user_mgr:init/1 states that the function might also
>> return
>> {'ok',{{'simple_one_for_one',100,1},[{'match_stream_user',{'match_stream_user','start_link',[]},'transient','brutal_kill','worker',['match_stream_user']}]}}
>> but the inferred return is none()
>> match_stream_user_mgr.erl:33: Function init/1 has no local return
>
> You can check match_stream_user_mgr:init/1
> <https://github.com/inaka/match_stream/blob/master/src/match_stream_user_mgr.erl>
> code... it's fairly simple:
>
>
>> -spec init([]) -> {ok, {{simple_one_for_one, 100, 1},
>> [{match_stream_user, {match_stream_user, start_link, []}, transient,
>> brutal_kill, worker, [match_stream_user]}]}}.
>> init([]) ->
>> {ok, {{simple_one_for_one, 100, 1},
>> [{match_stream_user, {match_stream_user, start_link, []},
>> transient, brutal_kill, worker, [match_stream_user]}]}}.
>
> Any clues?

Fernando,

In the code of your file you are including file "match_stream.hrl" 
(unnecessarily? because it is not used anywhere) which has the following 
record declaration:

-record(match_stream_user, {user_id :: match_stream:user_id(),
                             visit_count = 1 :: pos_integer()}).

This tells dialyzer that all 3-tuples tagged with the atom 
'match_stream_user' are intended to have a match_stream:user_id() in the 
second element and a pos_integer() in the third element of the tuple.

Still, in the file you are constructing the following 3-tuple:

	{match_stream_user, start_link, []}

which violates the record definition (on the 3rd element).

You cannot have both.  You have three options:

  1. Take out the include declaration
  2. Use a different tag for the tuple that you construct in the file
  3. Add the [] in the type of the visit_count field

The first option is the easiest; the second is most probably the thing 
you want to do here.

Kostis



More information about the erlang-questions mailing list