Elixir - why is there no compiler warning for these duplicate headers?

Viewed 82

Today while walking through some code I came across the following two function headers and realized that, as far as I can tell, they should be duplicates. Same number of parameters and no matches or guards to let us bypass the first one. But the compiler isn't giving me a warning that the second will never match. Any explanation why that would be?

  def update_display_cache(context, text, line_no, position, text, adjusted_text, _) do
  def update_display_cache(context, display_line, line_no, position, text, adjusted_text, _) do

I made a couple of simple functions with matching parameter lists, including one with the trailing _ parameter and they all gave the expected warning.
warning: this clause cannot match because a previous clause at line 24 always matches

I also copied and pasted the entire first function header and body without changes and still didn't get a warning.

Elixir 1.7.4

1 Answers

The param text appears two times in the first definition, adding the extra constraint that those two values have to be equal to match.

A simpler minimal example reproducing it:

  def equals?(a, a), do: true
  def equals?(_, _), do: false
Related