[erlang-questions] Warning not emitted on string matching clauses

Erik Søe Sørensen <>
Wed Apr 8 08:46:16 CEST 2015


It would of course make sense to have the compiler warn in this case.
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.
/Erik
Den 01/04/2015 20.43 skrev "Pierre Fenoll" <>:

> -module(wat_clauses).
> -export([authenticate_nouns/1]).
> authenticate_nouns([{<<"user_auth">>, _}]) -> 'true';
> authenticate_nouns([{<<"user_auth">>, [<<"recovery">>]}]) -> hi;
> authenticate_nouns(_Nouns) -> 'false'.
>
>
> In this code <https://gist.github.com/fenollp/c08e86bdf15b28552824> (or
> above), the second clause will never match (because of source-order).
> But erlc does not complain about it.
>
> Ferd on IRC mentioned that the compiler might feel free to reorder clauses.
> But the call wat_clauses:authenticate_nouns([{<<"user_auth">>,
> [<<"recovery">>]}])
> returns true instead of hi, so no reordering is done.
>
> Dialyzer does not complain either.
>
> Am I right in thinking we should have a warning about a never matching
> clause?
>
> --
> Pierre Fenoll
>
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150408/612966fd/attachment.html>


More information about the erlang-questions mailing list