<br><br><div class="gmail_quote">On 8 July 2012 07:13, Sven Heyll <span dir="ltr"><<a href="mailto:sven.heyll@gmail.com" target="_blank">sven.heyll@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Acutally in gen_server I find:<br>
<br>
-callback handle_cast(Request :: term(), State :: term()) -><br>
{noreply, NewState :: term()} |<br>
{noreply, NewState :: term(), timeout() | hibernate} |<br>
{stop, Reason :: term(), NewState :: term()}.<br>
<br>
Why not define it this way:<br>
<br>
-callback handle_cast(Request :: term(), State) -><br>
{noreply, State} |<br>
{noreply, State, timeout() | hibernate} |<br>
{stop, Reason :: term(), State}.<br>
<br>
Is this possible?? I think this would help well written apps that are<br>
careful with type consistency, and hurt only bad code - but one who<br>
writes bad code wouldn't invoke dialyzer.<br>
<br></blockquote><div>No, it is impossible. What type of State would be here?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
wbr<br>
Sven<br>
<br>
<br>
2012/7/6 Maxim Treskin <<a href="mailto:zerthurd@gmail.com">zerthurd@gmail.com</a>>:<br>
<div class="HOEnZb"><div class="h5">><br>
><br>
> On 6 July 2012 17:35, Stavros Aronis <<a href="mailto:aronisstav@gmail.com">aronisstav@gmail.com</a>> wrote:<br>
>><br>
>> Hi again,<br>
>><br>
>> The signature (or "success typing" in Dialyzer's terminology) is<br>
>> `my_module:handle_cast(term(),term()) -> {'noreply',term()}` because the<br>
>> second clause:<br>
>><br>
>> handle_cast(_Msg, State) -><br>
>> {noreply, State}.<br>
>><br>
>> will accept any terms as _Msg and State and return {noreply, State} in<br>
>> which State again is any term. In Dialyzer's type system, this {noreply,<br>
>> term()} return value will 'absorb' the definitely incorrect {noreply,<br>
>> {bugotak}} as {bugotak} is also a term(). From that point on, Dialyzer can<br>
>> assume that term() might also be #state{} and emit no warnings. This happens<br>
>> because Dialyzer checks the whole range of return values at once and not<br>
>> each particular clause. If all the return values were definitely different<br>
>> than #state{}, then and only then would Dialyzer warn you.<br>
>><br>
><br>
> Thanks for the clarification, Stavros! Now I understand how Dialyzer checks<br>
> types of function clauses.<br>
><br>
>><br>
>> Again, trying to check each particular return value against a given spec<br>
>> might be an interesting extension and we will consider it in the future.<br>
>><br>
><br>
> I hope so. It would be a significant level up!<br>
><br>
>><br>
>> Stavros<br>
>><br>
>> On Fri, Jul 6, 2012 at 11:39 AM, Maxim Treskin <<a href="mailto:zerthurd@gmail.com">zerthurd@gmail.com</a>> wrote:<br>
>>><br>
>>> I just really not understand. Function handle_cast returns, and returns<br>
>>> incorrect type according to -spec signature, right?<br>
>>> Why Dialyzer lose this information? It is sort of missbehaviour i think.<br>
>>><br>
>>> --<br>
>>> Max Treskin<br>
>><br>
>><br>
><br>
><br>
><br>
> --<br>
> Max Treskin<br>
><br>
</div></div><div class="HOEnZb"><div class="h5">> _______________________________________________<br>
> erlang-questions mailing list<br>
> <a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
> <a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br>Max Treskin<br>