[erlang-questions] Dialyzer warning: variable can never match since previous clauses completely covered the type

Tobias Lindahl tobias.lindahl@REDACTED
Wed Mar 25 17:59:48 CET 2009

David Sveningsson wrote:
> Lets say that foo looks like this:
> - -spec foo() -> ok | {error, atom()}.
> foo() ->
> 	ok.
> I get the same error. It is true that the function will only return ok,
> but I would like to reserve that it may return {error, atom()} in the
> future. It that possible?

To add the spec and have Dialyzer accept it: Yes.
To make Dialyzer be quiet about the dead code: No.

Dialyzer uses both the spec and the type it finds in the analysis. It 
finds that your function returns 'ok', which is ok since it does not 
contradict your spec.

However, it will not widen the return type to the one in the spec, but 
use the more precise type that it has found in the analysis.

A -spec can never make your types less precise.


More information about the erlang-questions mailing list