Undefined function __info__/1 (this function is auto-generated by the compiler and must always be called as a remote, as in __MODULE__.__info__/1)

hello guys :wave:

i’m trying to compile my module but i’m getting an error that info has to be called inside the module i am requiring another module.Here is the code :


defmodule  CallersContext do
  defmacro definfo do
    IO.puts("In macro's context (#{__MODULE__}).")

    quote do
      IO.puts("In caller's context (#{__MODULE__}).")

      def friendly_info do
        IO.puts("""
        My name is #{__MODULE__}
        My functions are #{inspect(__info__(:functions))}
        """)
      end
    end
  end
end

defmodule Mod do
  require CallersContext
  CallersContext.definfo()
  __info__(:CallersContext)
end


I’ve tried calling module.info but seems my implementation is incorrect. Advice on the correct way to require a module inside another module

The message is telling you that __info__/1 needs to be called from within a function. It’s not supported to call it from the module body - which makes sense since that would mean it’s being called at compile time and the module doesn’t exist yet.

2 Likes

so i should wrap

info
inside a function and move it to the CallersContext ??

i did this:


     My functions are #{inspect(__MODULE__.__info__(:functions))}

Thanks