<p dir="ltr">It would of course make sense to have the compiler warn in this case.<br>
However - if my understanding of the compiler implementation is correct - matching of binaries is handled specially, and apparently in such a manner that it doesn't realise that the two binary patterns are identical.<br>
/Erik</p>
<div class="gmail_quote">Den 01/04/2015 20.43 skrev "Pierre Fenoll" <<a href="mailto:pierrefenoll@gmail.com">pierrefenoll@gmail.com</a>>:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div dir="ltr"><div><div><pre style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;margin-top:0px;margin-bottom:0px;width:748px;color:rgb(51,51,51);line-height:16.7999992370605px"><div><span style="line-height:16.7999992370605px">-module(wat_clauses).</span><br></div><div><span style="line-height:16.7999992370605px">-export([authenticate_nouns/1]).</span><span style="line-height:16.7999992370605px"> </span></div><div>authenticate_nouns([{<<"user_auth">>, _}]) -> 'true';
</div><div>authenticate_nouns([{<<"user_auth">>, [<<"recovery">>]}]) -> hi;
</div><div>authenticate_nouns(_Nouns) -> 'false'.
</div><div> </div></pre></div><div><a href="https://gist.github.com/fenollp/c08e86bdf15b28552824" target="_blank">In this code</a> (or above), the second clause will never match (because of source-order).</div><div>But erlc does not complain about it.</div><div><br></div><div>Ferd on IRC mentioned that the compiler might feel free to reorder clauses.</div><div>But the call <span style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:11.8999996185303px;line-height:19.0400009155273px;background-color:rgba(0,0,0,0.0392157)">wat_clauses:authenticate_nouns([{<<"user_auth">>, [<<"recovery">>]}])</span></div><div>returns true instead of hi, so no reordering is done.</div><div><br></div><div>Dialyzer does not complain either.</div><div><br></div><div>Am I right in thinking we should have a warning about a never matching clause?</div><div><br></div><div>-- </div><div>Pierre Fenoll</div></div><div><br></div></div></div></div>
</div></div>
<br>_______________________________________________<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" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></blockquote></div>