Bugs in Erlang code

Raimo Niskanen <>
Thu Mar 17 09:31:26 CET 2005


If the second argument to do_yield is corrected to 'infinity' it will 
not return 'timeout', I would say that is not a bug, just mere ugly.

So the bug is that 'infinity' is misspelled as 'infinite' in two places.

 (Alexey Shchepin) writes:

> Hello, Kostis!
> 
> On Thu, 17 Mar 2005 01:14:39 +0100 (MET), you said:
> 
>  KS> I am really amazed at some of the bugs we have been able to find in
>  KS> supposedly well-tested Erlang code using the new type analysis.
> 
>  KS> Many of them, we've reported directly to the OTP team and they are already
>  KS> fixed.  Some others we've finding every day as the analysis gets stronger
>  KS> and stronger.  For example, today I've come across the following code (in
>  KS> kernel/src/rpc.erl).
> 
>  KS> =======================================================================
>  KS> yield(Key) when pid(Key) ->
>  KS>     {value, R} = do_yield(Key, infinite),
>  KS>     R.
> 
> do_yield can return 'timeout', so there can be 'badmatch' error, and second
> argument should be 'infinity'.
> 
>  KS> 
>  KS> nb_yield(Key, infinite) when pid(Key) ->
>  KS>     do_yield(Key, infinite);
> 
> Again 'infinity'.
> 
>  KS> nb_yield(Key, Timeout) when pid(Key), integer(Timeout), Timeout >= 0 ->
>  KS>     do_yield(Key, Timeout).
>  KS> 
>  KS> nb_yield(Key) when pid(Key) ->
>  KS>     do_yield(Key, 0).
>  KS> 
>  KS> do_yield(Key, Timeout) ->
>  KS>     receive
>  KS>         {Key,{promise_reply,R}} ->
>  KS>             {value,R}
>  KS>         after Timeout ->
>  KS>             timeout
>  KS>     end.
>  KS> =========================================================================
> 
> The rest looks ok for me.
> 
>  KS> There are actually two (and arguably three) errors in the above code!
> 
>  KS> Dialyzer found them.
> 
>  KS> QUIZ for the seasoned Erlang programmers: Who can spot them?
> 

-- 

/ Raimo Niskanen, Erlang/OTP, Ericsson AB



More information about the erlang-questions mailing list