[erlang-questions] Dialyzer and apply

Kostis Sagonas kostis@REDACTED
Sun Mar 29 10:58:26 CEST 2009


Ahmed Diaa wrote:
> Hello there ,
> I started using Dialyzer lately , and found it really usefull. But , I 
> had a case that I expected dialyzer to discover but it didn't.
> 
> The case occurs when using erlang:apply/3 or timer:apply_after/4
> Here's the example
> 
> -module(dtest).
> 
> -export([foo/0]).
> 
> foo()->
>     timer:apply_after(100,?MODULE, bar, [ ]),
>     erlang:apply(?MODULE,bar,[ ]).
> 
> When running the dialyzer for this module , it didn't discover the call 
> to a missing function.
> 
> Wouldn't it be nice if dialyzer could discover such cases?

Yes, it would be but:

  - there is very little reason to use erlang:apply/3 when the module
    name, function name and the number of arguments are known (like in
    your example, where you should really use ?MODULE:bar() instead)

  - detecting the timer:apply_after/4 missing functions would mean that
    dialyzer has hard-coded information about the timer module and in
    Erlang there is nothing that prevents you from using your own 'timer'
    module in your application

  - detecting missing funcyions is not dialyzer's main objective (there
    are other tools like xref that are supposed to be used for such
    purposes -- although I am not sure whether even that one detects that
    bar/0 is a missing function when used in timer:apply_after/4).

Kostis



More information about the erlang-questions mailing list