<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Hello, <br>
<div class="moz-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>
</body>
</html>