Dialyzer bug or some problem with my code
Anthony Molinaro
anthonym@REDACTED
Tue Mar 22 00:51:28 CET 2011
Hi,
Not sure if this is a bug or not, but the attached file exhibits the
following.
% erlc tmp.erl
% erl -eval 'tmp:test(), init:stop()' -noshell
All 2 tests passed.
% dialyzer -Wno_opaque tmp.erl
Checking whether the PLT /Users/molinaro/.dialyzer_plt is up-to-date... yes
Proceeding with analysis...
tmp.erl:19: Function key_in_dict/2 has no local return
Unknown functions:
eunit:test/1
done in 0m0.63s
done (warnings were emitted)
Using R14B02. As far as I can tell the key_in_dict function always returns
so I'm not sure why it would have no local return. I can always work around
with -Wno_return but I already don't like the fact that I have to work around
dict being an opaque type with -Wno_opaque (is that ever going to get fixed?).
-Anthony
--
------------------------------------------------------------------------
Anthony Molinaro <anthonym@REDACTED>
-------------- next part --------------
-module (tmp).
-export ([in_thing/2]).
-include_lib("eunit/include/eunit.hrl").
-spec in_thing(_,_) -> boolean().
in_thing (A, B) ->
case B of
Dict when is_tuple (B) andalso element (1, B) =:= dict ->
key_in_dict (A, Dict);
List when is_list (B) ->
key_in_list (A, List);
_ ->
false
end.
-spec key_in_dict(list(),dict()) -> boolean().
key_in_dict (Key, Dict) when is_list (Key) ->
dict:is_key (Key, Dict)
orelse dict:is_key (list_to_binary(Key), Dict)
orelse dict:is_key (list_to_atom(Key), Dict).
-spec key_in_list(list(),[{any(),any()}]) -> boolean().
key_in_list (Key, List) when is_list (Key), is_list (List) ->
proplists:is_defined (Key, List)
orelse proplists:is_defined (list_to_binary(Key), List)
orelse proplists:is_defined (list_to_atom(Key), List).
-ifdef(EUNIT).
-define(ALIST1, [{"A","B"},{"C","D"}]).
-define(ALIST2, [{'A',"B"},{'C',"D"}]).
-define(ALIST3, [{<<"A">>,"B"},{<<"C">>,"D"}]).
in_thing_dict_test () ->
?assertEqual (in_thing("A",dict:from_list (?ALIST1)), true),
?assertEqual (in_thing("A",dict:from_list (?ALIST2)), true),
?assertEqual (in_thing("A",dict:from_list (?ALIST3)), true),
?assertEqual (in_thing("B",dict:from_list (?ALIST1)), false),
?assertEqual (in_thing("B",dict:from_list (?ALIST2)), false),
?assertEqual (in_thing("B",dict:from_list (?ALIST3)), false).
in_thing_list_test () ->
?assertEqual (in_thing("A",?ALIST1), true),
?assertEqual (in_thing("A",?ALIST2), true),
?assertEqual (in_thing("A",?ALIST3), true),
?assertEqual (in_thing("B",?ALIST1), false),
?assertEqual (in_thing("B",?ALIST2), false),
?assertEqual (in_thing("B",?ALIST3), false).
-endif.
More information about the erlang-questions
mailing list