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

Dmitry Belyaev rumata-estor@REDACTED
Thu Apr 22 16:32:18 CEST 2010


Yes, I use R1303.
But the desired warning is about line 11: check_atom(AtomBad) would fail 
because AtomBad type is 'bad'. Or at least ('good'|'bad').

Kostis Sagonas wrote:
>
> Dmitry Belyaev wrote:
>> I thought type specs are made for external typechecks. Ok. Now I have 
>> this code:
>> -module(test).
>>
>> -export([start/0]).
>>
>> -spec start() -> ok.
>> start() ->
>>    AtomBad = get_atom(1),
>>    AtomGood = get_atom(2),
>>    check_atom(AtomBad),
>>    case check_atom(AtomGood) of
>>        ok -> ok;
>>        error -> error
>>    end.
>>
>> -spec get_atom(any()) -> good | bad.
>> get_atom(1) ->
>>    bad;
>> get_atom(_) ->
>>    good.
>>
>> -spec check_atom(good | nice) -> ok | error.
>> check_atom(Atom) ->
>>    ok.
>>
>> It doesn't warn me about check_atom(AtomBad).
>
> It does; see below.  You are using an older Erlang/OTP.
> Upgrade to R13B04.
>
> Kostis
>
> test.erl:12: The pattern 'error' can never match the type 'ok'
> test.erl:21: The specification for test:check_atom/1 states that the 
> function might also return 'error' but the inferred return is 'ok'
>
> ________________________________________________________________
> 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