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?

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: https://github.com/phoenixframework/phoenix/blob/master/mix.exs

Where Next?

Popular in Questions Top

sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
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
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
jc00ke
Expanding on this topic: https://forum.elixirforum.net/t/map-typespec-question/19217 Let’s say I have a map with required and optional k...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
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...
3268 119930 1237
New
peerreynders
Manning 2016 Halloween weekend sale via Deal of the Day Friday, October 28 - Half off all MEAPs - code WM102816LT Saturday, October 29 ...
326 29600 154
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
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
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
sergio
I couldn’t find any guides that worked well with Phoenix 1.6.0 and esbuild. I hope this helps people test the waters and eases you into t...
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New

We're in Beta

About us Mission Statement