<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hi bengt,<div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre"> </span>This would be my guess:</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre"> </span>The spec for <i class="">sets:is_dets_file/1</i> says…</div><div class=""><span class="Apple-tab-span" style="white-space:pre"> </span></div><div class=""><span class="Apple-tab-span" style="white-space:pre"> </span>-spec is_dets_file(Filename) -> boolean() | {'error', Reason} when<br class=""><span class="Apple-tab-span" style="white-space:pre"> </span> Filename :: file:name(),<br class=""><span class="Apple-tab-span" style="white-space:pre"> </span> Reason :: term().</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre"> </span>That means that, for it to work, its parameter must be of type <i class="">file:name().</i></div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre"> </span>Therefore, in your code, dialyzer infers that your variable <b class="">O</b> is, in fact, a <i class="">file:name()</i> which of course doesn’t match with <i class="">{error, Reason}</i>.</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre"> </span>When you remove the first argument for <i class="">key/2</i>, you’re basically removing that restriction… dialyzer can no longer infer anything about the type of <b class="">O</b> and therefore is silent.</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre"> </span>Hope this helps.<br class=""><div class="">
<div style="color: rgb(0, 0, 0); font-family: 'Trebuchet MS'; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class=""><span id="docs-internal-guid-e691a4cc-056a-0210-b8b7-ea8d87d888ad" class=""><span style="font-size: 11pt; font-family: Arial; font-weight: 700; font-variant-ligatures: normal; font-variant-position: normal; font-variant-numeric: normal; font-variant-alternates: normal; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;" class=""><br class="Apple-interchange-newline"><hr class=""></span></span><div class=""><b class=""><i class=""><a href="http://about.me/elbrujohalcon" class="">Brujo Benavides</a></i></b></div></div></div><div style="color: rgb(0, 0, 0); font-family: 'Trebuchet MS'; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><b class=""><br class=""></b></div><br class="Apple-interchange-newline">
</div>
<div><br class=""><blockquote type="cite" class=""><div class="">On 17 Aug 2018, at 12:56, bengt e <<a href="mailto:cean.ebengt@gmail.com" class="">cean.ebengt@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Greetings,<div class=""><br class=""></div><div class="">This is on Erlang 20.3. I am at work, so if anybody could test on 21 that would be nice.</div><div class=""><br class=""></div><div class="">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):</div><div class="">src/test_dialyzer.erl</div><div class=""> 19 </div><div class="">: The pattern <_, {'error', _Reason}> can never match the type <boolean() | {'error',_},[atom() | [any()] | char()]></div><div class=""><br class=""></div><div class="">If I remove the first argument to key/2, Dialyzer is silent.</div><div class="">Is there anybody that would like to explain why I get the warning?</div><div class="">Is it some kind of interference between type specs? Ie, is_dets_file/1 hides {error, Reason} from oldest/1 ?</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Best Wishes,</div><div class="">bengt</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><div class="">-module( test_dialyzer ).</div><div class=""><br class=""></div><div class="">%% API exports</div><div class="">-export( [key/1] ).</div><div class=""><br class=""></div><div class="">%%====================================================================</div><div class="">%% API functions</div><div class="">%%====================================================================</div><div class=""><br class=""></div><div class="">-spec( key(Name::file:filename()) -> ok ).</div><div class="">key( Name ) -></div><div class=""><span style="white-space:pre" class=""> </span>O = oldest( file:list_dir(Name) ),</div><div class=""><span style="white-space:pre" class=""> </span>key( dets:is_dets_file(O), O ).</div><div class=""><br class=""></div><div class="">%%====================================================================</div><div class="">%% Internal functions</div><div class="">%%====================================================================</div><div class=""><br class=""></div><div class="">key( _, {error, _Reason} ) -> ok;</div><div class="">key( _, _ ) -> ok.</div><div class=""><br class=""></div><div class="">oldest( {ok, [H | _]} ) -> H;</div><div class="">oldest( {error, Reason} ) -> {error, Reason}.</div><div class=""><br class=""></div></div></div>
_______________________________________________<br class="">erlang-questions mailing list<br class=""><a href="mailto:erlang-questions@erlang.org" class="">erlang-questions@erlang.org</a><br class="">http://erlang.org/mailman/listinfo/erlang-questions<br class=""></div></blockquote></div><br class=""></div></body></html>