Adam Sandler — The Cobbler (2014)

Running Dialyzer

Dialyzer is both a shell tool that you can run on your console and, of course, en Erlang application that you can run from within your Erlang VMs. For Katana-Test’s meta test suite, we needed to run dialyzer from code, as you might have expected.

A simplified version of what we needed to do is shown below…

dia.erl

That module contains 2 main functions: plt/0 and run/1. They both end up calling dialyzer:run/1 with different options. The main difference is analysis_type: While plt/0 is used to build the plt that dialyzer needs to analyze your code, run/1 is used to actually check the successful types in your modules and functions.

dialyzer:run/1 returns a list of warnings in Erlang form (more on that below) that you can later run through dialyzer:format_warning/1,2 to get proper messages in string() format.

So far, so good. Now, let’s see what happens when we try to analyze this module itself, as we tried to do with our meta suite…

1> c(dia, [debug_info]).

{ok,dia}

2> dia:plt().

Creating PLT dia.plt ... done in 0m11.30s

ok

3> dia:run(["dia.beam"]).

Checking whether the PLT dia.plt is up-to-date... yes

Proceeding with analysis... done in 0m0.15s

dia.erl:28: The call dialyzer:format_warning(Warning::{atom(),{_,_},{_,_}}) breaks the contract (raw_warning()) -> string()

ok

4>

Oh, man! We’re breaking a contract!