Hello
given the following module
defmodule X do
def foo(a, c), do: foo(a, :b, c)
def foo(a, b \\ "2", c \\ "3"), do: IO.inspect {a, b, c}
end
Elixir emits the following warning
Interactive Elixir (1.8.1) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> defmodule X do
...(1)> def foo(a, c), do: foo(a, :b, c)
...(1)> def foo(a, b \\ "2", c \\ "3"), do: IO.inspect {a, b, c}
...(1)> end
warning: this clause cannot match because a previous clause at line 2
always matches
iex:3
{:module, X,
<<70, 79, 82, 49, 0, 0, 5, 104, 66, 69, 65, 77, 65, 116, 85, 56, 0, 0, 0,
139,
0, 0, 0, 16, 8, 69, 108, 105, 120, 105, 114, 46, 88, 8, 95, 95, 105, 110,
102, 111, 95, 95, 7, 99, 111, 109, 112, ...>>, {:foo, 3}}
however it is possible to call both clauses:
iex(2)> X.foo(:a, :c)
{:a, :b, :c}
{:a, :b, :c}
iex(3)> X.foo(:a, :z, :c)
{:a, :z, :c}
{:a, :z, :c}
It would be more clear if Elixir could report the actual clauses that
cannot be called.
Thanks
Mário Guimarães
--
You received this message because you are subscribed to the Google Groups
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/elixir-lang-core/206dee43-d89a-4ff1-97ed-f64e9432d983%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.