I'm getting what I consider to be a rather strange warning when trying to compile an Elixir module (using Elixir 1.3.2 and Erlang R19). The code is from the book Introducing Elixir:
defmodule Drop do
def fall_velocity(distance) do
:math.sqrt(2 * 9.8 * distance)
end
def fall_velocity(distance, gravity \\ 9.8) do
:math.sqrt(2 * gravity * distance)
end
end
When I compile it, the shell says:
warning: this clause cannot match because a previous clause at line 2 always matches
drop.ex:6
Line 6 is the second function definition, and line 2 is the first one.
However, when I use the code, it works fine:
iex(12)> Drop.fall_velocity(20)
19.79898987322333
iex(13)> Drop.fall_velocity(20, 1.6)
8.0
What, then, is the meaning of that warning?