[erlang-questions] Dialyzer and apply

Ahmed Diaa ahmed.diaa@REDACTED
Sun Mar 29 11:39:47 CEST 2009


Hello Kostis , 
Thanks for your reply , 
- Well ,as the dialyzer use guide says, it "identifies software
discrepancies"
and it's already discovering calls to missing functions , that's why I
expected that behaviour 
- I used apply in the example just to include that case , but I agree
that it's rarely used when M,F,A are known.
- I understand your concern about hard-coded information
- Thanks for pointing out xref , it did discover the case of
erlang:apply/3 , but didn't discover the timer:apply_after/4 one.


-----Original Message-----
From: Kostis Sagonas [mailto:kostis@REDACTED] 
Sent: Sunday, March 29, 2009 10:58 AM
To: erlang-questions@REDACTED
Cc: Ahmed Diaa
Subject: Re: [erlang-questions] Dialyzer and apply

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