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

Dmitry Belyaev rumata-estor@REDACTED
Thu Apr 22 15:57:09 CEST 2010


Cause I may extend this function in the future. Or got this version 
after refactoring and don't want to change code that uses it.


Kostis Sagonas wrote:
>
> 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
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
>
>



More information about the erlang-questions mailing list