[erlang-questions] Make dialyzer use -callback types in behaviour module

Sölvi Páll Ásgeirsson solvip@REDACTED
Mon Aug 20 15:24:26 CEST 2018


I think that the way I'd prefer is to type the record field(or
whatever) that are used to store HandlerMod, just like we do when
typing other things.

i.e., you should be able to define your state as something like:
-record(state, { handler_mod :: some_behaviour_type()

And dialyzer would figure out that handler_mod should infer to a
module that implements that behaviour type.
That way, no unexpected magic is going on and the typing of the
callback will be no different from the typing of other things that you
might have in your state.

Sölvi Páll Á.
On Mon, Aug 20, 2018 at 7:30 AM Bach Le <thebullno1@REDACTED> wrote:
> Currently, `-callback` declaration only affects how dialyzer works on the callback module. Those info are ignored in the behaviour module when a dynamic call is made: `HandlerMod:callback_fun()`. Right now, I am rewriting some behaviour specs and having dialyzer check the types would be great.
> I can think of two ways to do this:
> * Make dialyzer consider all dynamic calls in a module that declare `-callback` to be calls to the matching callback functions. I have no idea about dialyzer's internal though.
> * Create a parse transform that is only called when using dialyzer. Each `-callback` will have a matching wrapper function e.g: `-callback foo(number()) -> ok` will generate `
> `'$call_foo'(module(), number()) -> ok`. All dynamic calls (e.g: `HandlerMod:foo(42)`) will be rewritten to use those wrappers (`'$call_foo'(HandlerMod, 42)`). IIRC, there are ways to pass compiler options into dialyzer.
> What are your thoughts?
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions

More information about the erlang-questions mailing list