[erlang-questions] dialyzer: user-defined types just synonyms?
Dmitry Belyaev
rumata-estor@REDACTED
Thu Apr 22 16:26:09 CEST 2010
It would be nice if it would intersect spec parameters and check spec
result contain what dialyzer infers.
So, if I have
-spec function(A) -> B.
and dialyzer finds that real type as function(C) -> D then it would
check that C contains A and B contains D and its final type would be
function(C) -> B.
Tobias Lindahl wrote:
> 2010/4/22 Dmitry Belyaev <rumata-estor@REDACTED>:
>
>> 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?
>>
>
> Once again, no. You cannot widen a success typing of a function using
> a spec. The type of the function will be the intersection of the type
> in the spec and whatever type Dialyzer infers for the function. In
> this case it finds that the error clause is unreachable since the
> function unconditionally returns ok.
>
> Tobias
>
>
More information about the erlang-questions
mailing list