I have a macro that puts catch-all functions in the end of the module, so resulting module looks something like:
defmodule Module1 do
<module body>
## Generated catch-all functions
def fun1(_, _), do: :ok
## ..more catch-all functions...##
end ## of module
The problem I'm trying to solve is to suppress warnings
"this clause cannot match because a previous clause at line XX always matches" in case the user of macro will have, for instance
def fun1(arg1, arg2), do: ...
in the body of the module.
I guess I can go through module's body AST and do some analysis of function signatures before generating catch-all functions, but it seems to be a lot of work. Is there any other way?
def MyServer do use GenServer end { :ok, pid } = GenServer.start_link(MyServer, 100) send pid, :hello
:hello , but:def MyServer do use GenServer def handle_info(:my_msg, state) do IO.puts :my_msg {:noreply, state} end end { :ok, pid } = GenServer.start_link(MyServer, 100) send pid, :hello
I'll get "no function clause" exception – Boris Okner