[erlang-bugs] Wrong "this clause cannot match because of a previous clause" warning

José Valim jose.valim@REDACTED
Sun Jun 16 17:38:51 CEST 2013


Hello,

I have found a bug on the "cannot match clause" warning. Consider this
minimal case:

-module(foo).
-export([bar/0]).

bar() ->
  V = <<"hello">>,
  case is_binary(V) of
    false -> good;
    true  -> bad
  end.


When compiled, the code above spews the following warning:

$ erlc foo.erl
foo.erl:7: Warning: this clause cannot match because *a previous* clause at
line 8 always matches


In fact, the clause that always match is the following one and not the
previous one. One simple fix for this issue is to change the message to:

foo.erl:7: Warning: this clause cannot match because *another* clause at
line 8 always matches


One may attempt a smarter fix by checking if the order of the lines but
that would could still generate invalid warnings in case someone decides to
inline case into a single line.


*José Valim*
www.plataformatec.com.br
Skype: jv.ptec
Founder and Lead Developer
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-bugs/attachments/20130616/bbc00c67/attachment.htm>


More information about the erlang-bugs mailing list