[erlang-questions] Dialyzer confused by several clauses?

Paul Guyot pguyot@REDACTED
Mon Aug 18 09:53:51 CEST 2008


Updating some code, I realized that dialyzer did not complain about  
an incorrect specification.

Here is a simple code that it accepts:

-type(dict() :: any()).

-spec(clause/2::(integer(), dict()) -> tuple()).
clause(0, Dict) ->
     case orddict:find(0, Dict) of
         {ok, Value} -> Value;
         error -> 0.0
clause(Integer, Dict) ->
     case orddict:find(Integer, Dict) of
         {ok, Value} -> Value / Integer;
         error -> 0.0

The real contract is:
-spec(clause/2::(integer(), dict()) -> float()).

An implied contact would be:
-spec(clause/2::(integer(), dict()) -> float() | any()).

But this contract is certainly incompatible with the code:
-spec(clause/2::(integer(), dict()) -> tuple()).

Am I doing something wrong or is it a known limitation?



More information about the erlang-questions mailing list