[erlang-questions] dialyzer: user-defined types just synonyms?

Kostis Sagonas kostis@REDACTED
Thu Apr 22 15:47:41 CEST 2010


Dmitry Belyaev wrote:
> And one more question. I have a code:
> -module(test).
> 
> -export([start/0]).
> 
> -spec start() -> ok.
> start() ->
>    %%check_atom(bad),
>    case check_atom(good) of
>        ok -> ok;
>        error -> error
>    end.
> 
> -spec check_atom(good | nice) -> ok | error.
> check_atom(Atom) ->
>    ok.
> 
> Dialyzer shows:
> test.erl:10: The pattern 'error' can never match the type 'ok'
> I'd like it to pay more attention to -spec than to function's body so I 
> wouldn't get this message. Is it possible?

You've defined two functions in your example, one that returns either 
'ok' or 'error' and you give it a spec that says it only returns 'ok' 
and one that clearly returns 'ok' only and your spec claims it returns 
'error' also.  Why on earth you would you want to do that in your 
program?  If you want obfuscated code, write in C instead.

Dialyzer has detected that you are clearly an evil programmer :-)
Why should it be nice to you?

Kostis


More information about the erlang-questions mailing list