Bugs in Erlang code

Alexey Shchepin <>
Thu Mar 17 02:58:17 CET 2005

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> 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> nb_yield(Key) when pid(Key) ->
 KS>     do_yield(Key, 0).
 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?

More information about the erlang-questions mailing list