Erlang/OTP Forums

Author Message

<  Erlang questions mailing list  ~  Dialyzer warning

Guest
Posted: Fri Sep 23, 2011 3:34 pm Reply with quote
Guest
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
Guest
Posted: Fri Sep 23, 2011 4:17 pm Reply with quote
Guest
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
_______________________________________________
erlang-questions mailing list
erlang-questions@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions
Post received from mailinglist
Guest
Posted: Fri Sep 23, 2011 4:23 pm Reply with quote
Guest
Oh! That was a tricky one!

Thanks Kostis Smile

On 23/09/2011, at 13:17, Kostis Sagonas wrote:

> 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
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@erlang.org
> http://erlang.org/mailman/listinfo/erlang-questions

_______________________________________________
erlang-questions mailing list
erlang-questions@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions
Post received from mailinglist

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum