[erlang-questions] -callback directives with Dialyzer

Matthew Fitzpatrick <>
Tue Sep 15 19:39:00 CEST 2015


Hey All,

This was done with Erlang R15B02.

The example code and problem can also be seen here:
https://github.com/Ceryni/cuddly-octo-adventure

Based on everything I've been reading and looking at, it seemed like if I
have a behavior like this...

```erlang
% dude.erl
-module(dude).
-callback hey_dude(Say :: string()) -> Res :: string().
```

And I then implement it...

```erlang
% no_spec_dude.erl
-module(no_spec_dude).
-behaviour(dude).
-export([hey_dude/1]).
hey_dude(Say) ->
  lists:flatten(io_lib:format("Hey Dude, ~p", [Say])).
```

And finally, I try to use it...

```erlang
% runner.erl
-module(runner).
-export([run/0]).
-spec run() -> ok.
run() ->
  io:format("~p", [no_spec_dude:hey_dude(42)]).
```

If i run dialyzer with these 3 files, It should complain about a contract
violation right? Except I'm running into the problem of that its not. I
created a sample repo with the output of dialyzer here:
https://github.com/Ceryni/cuddly-octo-adventure. If I explicitly define
`-spec` then it works as expected and barks at me for using an integer
instead of a string, but I thought dialyzer would use the -callback? Any
thoughts on what I'm doing wrong here? Maybe using dialyzer incorrectly? My
Erlang SDK is too old? Just trying to figure out what's going on.

Thanks in advance!
-Matt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150915/7b8a0c3f/attachment.html>


More information about the erlang-questions mailing list