Credence.Pattern.NoDuplicateFunctionClauses
(credence v0.8.0)
Copy Markdown
Detects duplicate function clauses with identical argument patterns.
In Elixir, a second clause whose argument patterns are structurally identical
to an earlier clause is unreachable — the first clause always matches first.
The compiler emits "this clause cannot match because a previous clause always
matches" which blocks compilation under --warnings-as-errors.
Two clauses have identical patterns when their arguments normalize to the same structure: bare variables are positionally equivalent regardless of name, and literal/structural patterns must match exactly.
Bad
defmodule Example do
def bar(x, y), do: {x, y}
def bar(x, y), do: {x, y}
endGood
defmodule Example do
def bar(x, y), do: {x, y}
end