[erlang-questions] Some questions about dialyzer

Jesper Louis Andersen jesper.louis.andersen@REDACTED
Thu Dec 22 23:03:32 CET 2011

On 12/21/11 10:30 AM, Alexander Kuleshov wrote:
> And also i have message like:
> test.erl:161: Function test_func/2 will never be called
> But i have some test_func calls in my code in current file.
This usually means that the dialyzer has analyzed your code with the 
conclusion that even if your code contains calls to this function, other 
things limit the control flow in ways which means that these call sites 
can never be invoked. Thus it reports that your function never gets called.

It is often the case that some other dialyzer error it found is the 
culprit. Suppose a call chain f() -> g() -> h() where the dialyzer finds 
that f() will always fail before calling g(). Then h() is not reachable 
and the above error type will be reported. Now, fixing the problem 
around the f function will then make the error go away since now the 
chain is "enabled".

Note that the dialyzer is pretty powerful in what it finds. Since it is 
a very powerful static analyzer it can often close down entire control 
flow paths in your code based upon factually possible values that may 
flow along *other* paths. A call that looks benign, with no errors 
reported for it, may actually constrain the data flow in your program in 
such a way that the dialyzer sees the error/mistake on your part.

The hard part about the dialyzer is to understand what the error 
messages *mean*. Not literally what the contents of the error message 
are, that is usually pretty clear, but rather, what the semantics of 
your program were that provoked that error. But when you begin to 
understand how it finds mistakes and what it reports it becomes an 
indispensable tool for weeding :)

Jesper Louis Andersen
   Erlang Solutions Ltd., Copenhagen, DK

More information about the erlang-questions mailing list