[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


-----BEGIN PGP SIGNED MESSAGE-----
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.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.11 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAknLPCgACgkQ6pa1H/H5pqWNlwCgnvSZaNGfJZyTQ7PxbFLlMrji
cvsAn1/XruMU5S9T0ciItTKkRVQE4LZ3
=UMPO
-----END PGP SIGNATURE-----



More information about the erlang-questions mailing list