<div dir="ltr">Thank you very much. That makes sense. I can fix this.<div><br><div>My mistake was to think that Dialyzer knew the return value of oldest/1, since it is there, in the file. Whereas, to me, the spec for is_dets_file/1 is 'just a spec'. dets:is_dest_file( {not, "afile", 1} ) will return {error, Reason} and not crash.</div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Aug 17, 2018 at 6:05 PM, Brujo Benavides <span dir="ltr"><<a href="mailto:elbrujohalcon@gmail.com" target="_blank">elbrujohalcon@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space">Hi bengt,<div><br></div><div><span class="m_-2705086180644621121Apple-tab-span" style="white-space:pre-wrap">        </span>This would be my guess:</div><div><br></div><div><span class="m_-2705086180644621121Apple-tab-span" style="white-space:pre-wrap">  </span>The spec for <i>sets:is_dets_file/1</i> says…</div><div><span class="m_-2705086180644621121Apple-tab-span" style="white-space:pre-wrap">     </span></div><div><span class="m_-2705086180644621121Apple-tab-span" style="white-space:pre-wrap">  </span>-spec is_dets_file(Filename) -<wbr>> boolean() | {'error', Reason} when<br><span class="m_-2705086180644621121Apple-tab-span" style="white-space:pre-wrap">  </span>      Filename :: file:name(),<br><span class="m_-2705086180644621121Apple-tab-span" style="white-space:pre-wrap">   </span>      Reason :: term().</div><div><br></div><div><span class="m_-2705086180644621121Apple-tab-span" style="white-space:pre-wrap">    </span>That means that, for it to work, its parameter must be of type <i>file:name().</i></div><div><br></div><div><span class="m_-2705086180644621121Apple-tab-span" style="white-space:pre-wrap">   </span>Therefore, in your code, dialyzer infers that your variable <b>O</b> is, in fact, a <i>file:name()</i> which of course doesn’t match with <i>{error, Reason}</i>.</div><div><br></div><div><span class="m_-2705086180644621121Apple-tab-span" style="white-space:pre-wrap">        </span>When you remove the first argument for <i>key/2</i>, you’re basically removing that restriction… dialyzer can no longer infer anything about the type of <b>O</b> and therefore is silent.</div><div><br></div><div><span class="m_-2705086180644621121Apple-tab-span" style="white-space:pre-wrap">  </span>Hope this helps.<br><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;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div><span id="m_-2705086180644621121docs-internal-guid-e691a4cc-056a-0210-b8b7-ea8d87d888ad"><span style="font-size:11pt;font-family:Arial;font-weight:700;font-variant-ligatures:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap"><br class="m_-2705086180644621121Apple-interchange-newline"><hr></span></span><div><b><i><a href="http://about.me/elbrujohalcon" target="_blank">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;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><b><br></b></div><br class="m_-2705086180644621121Apple-interchange-newline">
</div>
<div><br><blockquote type="cite"><div><div class="h5"><div>On 17 Aug 2018, at 12:56, bengt e <<a href="mailto:cean.ebengt@gmail.com" target="_blank">cean.ebengt@gmail.com</a>> wrote:</div><br class="m_-2705086180644621121Apple-interchange-newline"></div></div><div><div><div class="h5"><div dir="ltr">Greetings,<div><br></div><div>This is on Erlang 20.3. I am at work, so if anybody could test on 21 that would be nice.</div><div><br></div><div>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>src/test_dialyzer.erl</div><div>  19 </div><div>: The pattern <_, {'error', _Reason}> can never match the type <boolean() | {'error',_},[atom() | [any()] | char()]></div><div><br></div><div>If I remove the first argument to key/2, Dialyzer is silent.</div><div>Is there anybody that would like to explain why I get the warning?</div><div>Is it some kind of interference between type specs? Ie, is_dets_file/1 hides {error, Reason} from oldest/1 ?</div><div><br></div><div><br></div><div>Best Wishes,</div><div>bengt</div><div><br></div><div><br></div><div><div>-module( test_dialyzer ).</div><div><br></div><div>%% API exports</div><div>-export( [key/1] ).</div><div><br></div><div>%%============================<wbr>==============================<wbr>==========</div><div>%% API functions</div><div>%%============================<wbr>==============================<wbr>==========</div><div><br></div><div>-spec( key(Name::file:filename()) -> ok ).</div><div>key( Name ) -></div><div><span style="white-space:pre-wrap">  </span>O = oldest( file:list_dir(Name) ),</div><div><span style="white-space:pre-wrap">       </span>key( dets:is_dets_file(O), O ).</div><div><br></div><div>%%============================<wbr>==============================<wbr>==========</div><div>%% Internal functions</div><div>%%============================<wbr>==============================<wbr>==========</div><div><br></div><div>key( _, {error, _Reason} ) -> ok;</div><div>key( _, _ ) -> ok.</div><div><br></div><div>oldest( {ok, [H | _]} ) -> H;</div><div>oldest( {error, Reason} ) -> {error, Reason}.</div><div><br></div></div></div></div></div>
______________________________<wbr>_________________<br>erlang-questions mailing list<br><a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br><a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/<wbr>listinfo/erlang-questions</a><br></div></blockquote></div><br></div></div></blockquote></div><br></div>