<div dir="ltr">Yes. Dialyzer collects all local calls to a non-exported function and analyses its body with the additional constraint that the arguments given to the function are only the ones in those calls. In such cases it may be able to infer types that are stronger than the relevant specs (you can get a warning about the spec itself by using the "-Wunderspecs" option).<div><br></div><div>You can eliminate the warning by e.g. exporting 'is_relation/2' or by using it locally in situations where it may also return `{true, ...}`.</div><div><br></div><div>Cheers!</div><div><br></div><div>Stavros</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Tue, Jan 17, 2017 at 4:22 PM Bastien Chamagne <<a href="mailto:bchamagne@idmog.com">bchamagne@idmog.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000" class="gmail_msg">
<p class="gmail_msg">Thank you for the quick reply Stavros!</p>
<p class="gmail_msg"> You mean that dialyzer inference is stronger than the defined
typespec?</p></div><div bgcolor="#FFFFFF" text="#000000" class="gmail_msg">
<p class="gmail_msg"><br class="gmail_msg">
</p>
<div class="m_9148131320878690777moz-cite-prefix gmail_msg">On 01/17/2017 04:08 PM, Stavros Aronis
wrote:<br class="gmail_msg">
</div>
<blockquote type="cite" class="gmail_msg">
<div dir="ltr" class="gmail_msg">Hi Bastien,
<div class="gmail_msg"><br class="gmail_msg">
</div>
<div class="gmail_msg">can it be the case that "is_relation/2" is only used
"locally" (i.e. within the module itself) and all such calls
to "is_relation/2" will return 'false'?</div>
<div class="gmail_msg"><br class="gmail_msg">
</div>
<div class="gmail_msg">This looks like a case where dialyzer has inferred such a
thing and thus complains about the pattern that can't match.</div>
<div class="gmail_msg"><br class="gmail_msg">
</div>
<div class="gmail_msg">Regards,</div>
<div class="gmail_msg"><br class="gmail_msg">
</div>
<div class="gmail_msg">Stavros</div>
</div>
<div class="gmail_extra gmail_msg"><br class="gmail_msg">
<div class="gmail_quote gmail_msg">On Tue, Jan 17, 2017 at 3:47 PM,
Bastien Chamagne <span dir="ltr" class="gmail_msg"><<a href="mailto:bchamagne@idmog.com" class="gmail_msg" target="_blank"><a class="m_9148131320878690777moz-txt-link-abbreviated gmail_msg" href="mailto:bchamagne@idmog.com" target="_blank">bchamagne@idmog.com</a></a>></span> wrote:<br class="gmail_msg">
<blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000" class="gmail_msg"> Hello, <br class="gmail_msg">
<div class="m_9148131320878690777m_-5358249171057988792moz-forward-container gmail_msg">
<p class="gmail_msg"> I'm trying to use dialyzer and I don't know how to
type functions that are written in "happy path" (may
crash).<br class="gmail_msg">
Here's a sample function that may or may not crash
depending if Field correspond to a relation field on
given Model:<br class="gmail_msg">
<tt class="gmail_msg"><br class="gmail_msg">
</tt><tt class="gmail_msg"> -spec is_relation(field(), model()) ->
{true, relation_type()} | false.</tt><tt class="gmail_msg"><br class="gmail_msg">
</tt><tt class="gmail_msg"><br class="gmail_msg">
</tt><tt class="gmail_msg"> %% @doc Sets a relation on the given
model.</tt><tt class="gmail_msg"><br class="gmail_msg">
</tt><tt class="gmail_msg"> -spec set_relation(field(), model(),
model()) -> model() | no_return().</tt><tt class="gmail_msg"><br class="gmail_msg">
</tt><tt class="gmail_msg"> set_relation(Field, RelatedModel, Model)
-></tt><tt class="gmail_msg"><br class="gmail_msg">
</tt><tt class="gmail_msg"> % On next line, I'm OK that this
function crashes if I try to set a relation on a
non-relation field </tt><tt class="gmail_msg"><br class="gmail_msg">
</tt><tt class="gmail_msg"> {true, RelationType} =
is_relation(Field, Model),</tt><tt class="gmail_msg"><br class="gmail_msg">
</tt><tt class="gmail_msg"> set_relation(Field, RelatedModel,
Model, RelationType).</tt><br class="gmail_msg">
<br class="gmail_msg">
Here's what dialyzer says:</p>
<p class="gmail_msg"><tt class="gmail_msg"> model.erl:180: Function set_relation/3 has no
local return</tt><tt class="gmail_msg"><br class="gmail_msg">
</tt><tt class="gmail_msg"> model.erl:181: The pattern {'true',
RelationType} can never match the type 'false'</tt><br class="gmail_msg">
<br class="gmail_msg">
Is there anything that I can do to inform dialyzer
that this is a OK behaviour for me?</p>
<p class="gmail_msg">Cheers!<br class="gmail_msg">
<br class="gmail_msg">
<i class="gmail_msg">ps: I'm using erlang 17 if that matters.</i><br class="gmail_msg">
<i class="gmail_msg">ps: Sorry if it's a duplicate, I can't find the
previous message on the archive.</i><br class="gmail_msg">
<br class="gmail_msg">
</p>
</div>
</div>
<br class="gmail_msg">
_______________________________________________<br class="gmail_msg">
erlang-questions mailing list<br class="gmail_msg">
<a href="mailto:erlang-questions@erlang.org" class="gmail_msg" target="_blank">erlang-questions@erlang.org</a><br class="gmail_msg">
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" class="gmail_msg" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br class="gmail_msg">
<br class="gmail_msg">
</blockquote>
</div>
<br class="gmail_msg">
</div>
</blockquote>
<br class="gmail_msg">
</div></blockquote></div>