[erlang-questions] Dialyzer and callbacks

Kostis Sagonas kostis@REDACTED
Thu Feb 20 13:12:46 CET 2014


On 02/20/2014 12:45 PM, Håkan Mattsson wrote:
> Where does dialyzer look for beam files containing
> behaviour_info(callbacks)?
>
> It does not seem like it cares about the code path. Neither -r, -pa nor
> ERL_LIBS seems to work. Putting the beam-files at stdlib/ebin does
> however work.
>
> A poor confused soul.

[You managed to confuse me too, so I hope the following answer does not 
make the situation worse...]


Dialyzer does not look at behaviour_info(callbacks) at all.

Instead it looks for

-callback ...

attributes (i.e. type declarations).

Take e.g. a look at the source code of gen_server:

  https://github.com/erlang/otp/blob/master/lib/stdlib/src/gen_server.erl

You will find no behaviour_info/1 function declared there; modern Erlang 
code has callback declarations instead (from which the behaviour_info/1 
function is automatically generated as shown below).

Eshell V6.0  (abort with ^G)
1> gen_server:behaviour_info(callbacks).
[{init,1},
  {handle_call,3},
  {handle_cast,2},
  {handle_info,2},
  {terminate,2},
  {code_change,3}]


Now, if your question is: where does Dialyzer look for a my_behav.beam 
file when it finds a -behaviour(my_behav). attribute in some file it 
analyzes, the answer is that either you also supply this file to the 
analysis or you make sure it's in the PLT (which might explain why you 
claim that it works when you put it in stdlib/ebin because presumably 
your PLT includes info about stdlib).

Kostis



More information about the erlang-questions mailing list