Using Dialyzer

Dialyzer analyzes code that runs on the Erlang VM, looking for potential errors. To use it with Elixir, we have to compile our source into .beam files and make sure that the debug_info compiler option is set (which it is when running mix in the default, development mode). Let’s see how to do that by creating a trivial project with two source files. We’ll also remove the supervisor that mix creates, because we don’t want to drag OTP into this exercise.

 
$ ​mix new simple
 
...​​
 
$ ​cd simple
 
$ ​rm lib/simple/supervisor.ex

Inside the project, let’s create a simple function. Being lazy, I haven’t implemented the body yet.

 
defmodule​ Simple ​do
 
@type​ atom_list :: list(atom)
 
@spec​ count_atoms(atom_list) :: non_neg_integer ...

Get Programming Elixir now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.