Qqwy

Qqwy

TypeCheck Core Team

Suppress 'Module.function_name' is not defined or private

I am working on a library where, amongst other things, some default modules are called for Elixir’s built-in types like Tuples and Lists.

I do this in a manner similar to how Protocols are internally defined, namely to iterate over a list of {guard, modulename} and inside this function I can delegate to that other module’s implementation:

defmodule FunLand do
  defmodule Builtin do
    def __builtin__ do
      [is_tuple: FunLand.Builtin.Tuple,
       is_atom: FunLand.Builtin.Atom,
       is_list: FunLand.Builtin.List,
       is_map: FunLand.Builtin.Map,
       is_bitstring: FunLand.Builtin.BitString,
       is_integer: FunLand.Builtin.Integer,
       is_float: FunLand.Builtin.Float,
       is_function: FunLand.Builtin.Function,
       is_pid: FunLand.Builtin.PID,
       is_port: FunLand.Builtin.Port,
       is_reference: FunLand.Builtin.Reference]
    end
  end
end


# Inside one of the Behaviour-defining modules:
for {guard, module} <- FunLand.Builtin.__builtin__ do
    def map(mappable, function) when unquote(guard)(mappable) do
      unquote(module).map(mappable, function)
    end
  end

This works, but I am getting a lot of warnings, because not all of the modules inside FunLand.Builtin.__builtin__ will actually define all of the functions that are delegated to them. Things like

warning: function FunLand.Builtin.Atom.map/2 is undefined or private

These warnings are thrown during macro expansion, i.e. after the modules are compiled.

Because I use behaviours, it is impossible to check inside my behaviour-defining modules if the other module defines a certain function (doing things like Enum.member?(ModuleName.__info__(:functions), {:map, 2})) because this will result in a deadlock of modules waiting for each other’s compilation.

So, I think that the best approach here, is to silence the warning. How can this be done?

First Post!

Qqwy

Qqwy

TypeCheck Core Team

A possible solution I’ve found is to use Kernel.apply/3. This might be a little bit slower, because of the extra apply step. If there is a way to really suppress the warning I’d rather do that.

Most Liked

michalmuskala

michalmuskala

There is a mix project option for excluding modules from the output.

You can add in project/0: xref: [exclude: [MyModule]].

Example of that is in phoenix: phoenix/mix.exs at main · phoenixframework/phoenix · GitHub

Where Next?

Popular in Questions Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs &amp; Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 131117 1222
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New

We're in Beta

About us Mission Statement