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

Magnus Henoch magnus@REDACTED
Wed Mar 25 14:45:53 CET 2009

David Sveningsson <ext@REDACTED> writes:

> -spec foo() -> ok | {error, reason}.

This is not what you meant to write.  You declare that foo returns
either the atom 'ok', or a tuple of two atoms, 'error' and 'reason'.

> foo() ->
> 	case random:uniform(10) of
> 		N when N > 5 -> ok;
> 		_ -> {error, foobar}
> 	end.

Dialyzer believes your spec, and finds that your code can not possibly
return {error, reason}.  Therefore, the only remaining possibility is

You could write the spec as {error, foobar}, {error, atom()} or {error,

Magnus Henoch, magnus@REDACTED
Erlang Training and Consulting

More information about the erlang-questions mailing list