Lack of warning for overlapping clauses with

Torben Hoffmann <>
Thu Jul 15 13:31:40 CEST 2010


I had a very large module where I could not figure out why a specific thing
was not happening and it turned out that the root of the problem was a
construct like the following:



f(N) when N==1; N==2 ->
f(1) ->

I would have hoped that the compiler or dialyzer would have caught that the
f(1) clause will never be executed, but that is not the case.
It seems that the use of the when-clause changes the game so that the
overlap is not detected.
I accept that I am shooting myself in the foot here, but I would have liked
to be helped by the compiler or dialyzer since figuring this one out after
going through hefty logs is not fun.

Now that I know this I can work around it, but it would be nice to get the
warning since the code in my f(N) branch is actually not that small. Of
course I could create a function to do the operation and rewrite like this:



f(1) ->
f(2) ->
f(1) ->

In which case the compiler will warn me about the overlap, but I find that
to be somewhat ugly.

Any comments on this?


More information about the erlang-questions mailing list