Nicolas Martyanoff — Brain dump About

Unknown type specifications with Dialyzer

I use Dialyzer a lot, and it has always been useful to expose various errors in my Erlang code.

Unfortunately, I recently discovered an unexpected behaviour: by default, Dialyzer ignores unknown types. It is very surprising and suddently makes me doubt any piece of Erlang code I ever wrote.

As it turns out, there is a Dialyzer flag to detect and report these unknown types. With Rebar3, it can be added to the dialyzer setting:

{dialyzer, [{warnings, [unknown]}]}.

Activating unknown type detection could lead to interesting Dialyzer failures, when a type is part of an unknown module. Care should be taken to list application dependencies in the application resource file.

In some cases, it is necessary to reference a type from a module whose application is not a dependency of the current project. In that case, the application in question can be added to the PLT with the plt_extra_apps option.

For example:

{dialyzer, [{plt_extra_apps, [public_key]},
            {warnings, [unknown]}]}.

Activating unknown type detection for all my Erlang projects has revealed various issues, so it is definitely an option I will keep enabled in the future.

Share the word!

Liked my article? Follow me on Twitter or on Mastodon to see what I'm up to.