4

I am using Dialyzer with a few custom behaviors, the problem is that when I do that, Dialyzer gives me this error:

src/max.erl:3: Callback info about the gen_strategy behaviour is not available

One thing I can't figure out is how to create that callback info. I would like to add this information to my behaviour, so I can get that much more testing out of Dialyzer.

aronisstav
  • 7,755
  • 5
  • 23
  • 48
Zachary K
  • 3,205
  • 1
  • 29
  • 36

1 Answers1

8

Starting with R15B, The Erlang/OTP compiler was upgraded so that it now handles a new module attribute, named -callback.

Example:

-callback init(Args :: term()) ->
    {ok, State :: term()} | {ok, State :: term(), timeout() | hibernate} |
    {stop, Reason :: term()} | ignore.

More about that here and here

aronisstav
  • 7,755
  • 5
  • 23
  • 48
Ward Bekker
  • 6,316
  • 9
  • 38
  • 61
  • I tried that, it didn't seem to work. when I put the -callback in the behavior module it didn't compile. when I put it in the other module it dailyzer still gave me the same errors – Zachary K Jun 21 '13 at 14:54
  • Probably dialyzer can't find the code / beam file for the behaviour. If the behaviour is in a rebar lib, make sure you pass `-r deps` to the dialyzer command. – Ward Bekker Jun 21 '13 at 17:45
  • Zachary, can you post some more info about the "didn't compile" error? I can definitely help as I developed this extension... If you have `-callback` attributes in a module and you either put it in the PLT or analyze it together with the module that has the `-behaviour` attribute, Dialyzer should recognize the behaviour and use the info for the analysis. I added another relevant documentation link to Ward's reply. – aronisstav Jun 24 '13 at 08:01
  • @aronisstav I recently tried to use a -callback with dialyzer but I'm not having much luck. I created [this repository](https://github.com/Ceryni/cuddly-octo-adventure) to elucidate my problem. Could you take a look and let me know what you think? – Ceryni Sep 15 '15 at 16:42
  • @Ceryni I just did! https://github.com/Ceryni/cuddly-octo-adventure/commit/e3f94cfc9a5dbbdea6b202a71fc0e9acf290043a#commitcomment-13243675 – aronisstav Sep 15 '15 at 17:52
  • @aronisstav Awesome! Thanks very much for the rapid feedback. For anyone coming after me in case the github repo dissappears or what have you... "Indeed! -callback specifications are not automatically applied to behaviour implementations, hence the need for your -spec. What -callback specifications do is ensure that the implementation itself conforms to the specification described by the behaviour..." In short, if you want to have dialyzer help check people calling your implementation function, you'll need to add a -spec to it. At least, this is what I'm understanding. – Ceryni Sep 15 '15 at 18:41