18 Aug 09:51
Dialyzer confused by several clauses?
From: Paul Guyot <pguyot <at> kallisys.net>
Subject: Dialyzer confused by several clauses?
Newsgroups: gmane.comp.lang.erlang.general
Date: 2008-08-18 07:53:51 GMT
Subject: Dialyzer confused by several clauses?
Newsgroups: gmane.comp.lang.erlang.general
Date: 2008-08-18 07:53:51 GMT
Hello,
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
end;
clause(Integer, Dict) ->
case orddict:find(Integer, Dict) of
{ok, Value} -> Value / Integer;
error -> 0.0
end.
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()).
(Continue reading)
RSS Feed