<div dir="ltr">Hi Bastien,<div><br></div><div>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><br></div><div>This looks like a case where dialyzer has inferred such a thing and thus complains about the pattern that can't match.</div><div><br></div><div>Regards,</div><div><br></div><div>Stavros</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jan 17, 2017 at 3:47 PM, Bastien Chamagne <span dir="ltr"><<a href="mailto:bchamagne@idmog.com" target="_blank">bchamagne@idmog.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000">
Hello, <br>
<div class="m_-5358249171057988792moz-forward-container">
<p> I'm trying to use dialyzer and I don't know how to type
functions that are written in "happy path" (may crash).<br>
Here's a sample function that may or may not crash depending if
Field correspond to a relation field on given Model:<br>
<tt><br>
</tt><tt> -spec is_relation(field(), model()) -> {true,
relation_type()} | false.</tt><tt><br>
</tt><tt><br>
</tt><tt> %% @doc Sets a relation on the given model.</tt><tt><br>
</tt><tt> -spec set_relation(field(), model(), model()) ->
model() | no_return().</tt><tt><br>
</tt><tt> set_relation(Field, RelatedModel, Model) -></tt><tt><br>
</tt><tt> % On next line, I'm OK that this function
crashes if I try to set a relation on a non-relation field </tt><tt><br>
</tt><tt> {true, RelationType} = is_relation(Field,
Model),</tt><tt><br>
</tt><tt> set_relation(Field, RelatedModel, Model,
RelationType).</tt><br>
<br>
Here's what dialyzer says:</p>
<p><tt> model.erl:180: Function set_relation/3 has no local
return</tt><tt><br>
</tt><tt> model.erl:181: The pattern {'true', RelationType}
can never match the type 'false'</tt><br>
<br>
Is there anything that I can do to inform dialyzer that this is
a OK behaviour for me?</p>
<p>Cheers!<br>
<br>
<i>ps: I'm using erlang 17 if that matters.</i><br>
<i>ps: Sorry if it's a duplicate, I can't find the previous
message on the archive.</i><br>
<br>
</p>
</div>
</div>
<br>______________________________<wbr>_________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/<wbr>listinfo/erlang-questions</a><br>
<br></blockquote></div><br></div>