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

David Sveningsson ext@REDACTED
Thu Mar 26 09:26:16 CET 2009

Hash: SHA1

Tobias Lindahl wrote:
> 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.
> Tobias

Ok, thanks.
Version: GnuPG v2.0.11 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org


More information about the erlang-questions mailing list