O'Reilly logo

Programming Elixir 1.2 by Dave Thomas

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

 $ ​​mix​​ ​​new​​ ​​simple
 ...
 $ ​​cd​​ ​​simple

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
 def​ count_atoms(list) ​do
 # ...
 end
 end

Let’s run dialyzer on our code. Because it works from .beam files, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required