Bugs in Erlang code

Kostis Sagonas kostis@REDACTED
Thu Mar 17 01:14:39 CET 2005


[ Apologies for the plug for Dialyzer, but I am currently quite excited. ]

  Intro: As part of Dialyzer, we have been developing a type
	 analysis for Erlang that is significantly different
	 that the one the current version of Dialyzer is using.
	 It is not totally usable yet, but it is very powerful.
	 Stay tuned for its release!


I am really amazed at some of the bugs we have been able to find
in supposedly well-tested Erlang code using the new type analysis.

Many of them, we've reported directly to the OTP team and they are
already fixed.  Some others we've finding every day as the analysis
gets stronger and stronger.  For example, today I've come across
the following code (in kernel/src/rpc.erl).

=======================================================================
yield(Key) when pid(Key) ->
    {value, R} = do_yield(Key, infinite),
    R.

nb_yield(Key, infinite) when pid(Key) ->
    do_yield(Key, infinite);
nb_yield(Key, Timeout) when pid(Key), integer(Timeout), Timeout >= 0 ->
    do_yield(Key, Timeout).

nb_yield(Key) when pid(Key) ->
    do_yield(Key, 0).

do_yield(Key, Timeout) ->
    receive
        {Key,{promise_reply,R}} ->
            {value,R}
        after Timeout ->
            timeout
    end.
=========================================================================

There are actually two (and arguably three) errors in the above code!

Dialyzer found them.

QUIZ for the seasoned Erlang programmers: Who can spot them?

Cheers,
Kostis




More information about the erlang-questions mailing list