[erlang-questions] Dialyzer warning has me baffled.

bengt e cean.ebengt@REDACTED
Fri Aug 17 17:56:55 CEST 2018


Greetings,

This is on Erlang 20.3. I am at work, so if anybody could test on 21 that
would be nice.

The source code below (the smallest I could make the original and still get
the warning) gives me the Dialyzer warning (line 19 is first/2):
src/test_dialyzer.erl
  19
: The pattern <_, {'error', _Reason}> can never match the type <boolean() |
{'error',_},[atom() | [any()] | char()]>

If I remove the first argument to key/2, Dialyzer is silent.
Is there anybody that would like to explain why I get the warning?
Is it some kind of interference between type specs? Ie, is_dets_file/1
hides {error, Reason} from oldest/1 ?


Best Wishes,
bengt


-module( test_dialyzer ).

%% API exports
-export( [key/1] ).

%%====================================================================
%% API functions
%%====================================================================

-spec( key(Name::file:filename()) -> ok ).
key( Name ) ->
O = oldest( file:list_dir(Name) ),
key( dets:is_dets_file(O), O ).

%%====================================================================
%% Internal functions
%%====================================================================

key( _, {error, _Reason} ) -> ok;
key( _, _ ) -> ok.

oldest( {ok, [H | _]} ) -> H;
oldest( {error, Reason} ) -> {error, Reason}.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20180817/c472613a/attachment.htm>


More information about the erlang-questions mailing list