I am trying to hook into the @doc deprecated: "message"
annotation using __on_definition__
.
defmodule ExampleCompiler do
def __on_definition__(env, _, fun, _, _, _) do
doc = Module.get_attribute(env.module, :doc)
IO.inspect(doc, label: fun)
end
end
defmodule DemoModule do
@on_definition ExampleCompiler
@doc "hello"
def hello() do
end
@doc deprecated: "hello2"
def hello2() do
end
end
Output of compilation:
hello: {11, "hello"}
hello2: nil
So, for some reason in the on_definition hook of the hello2 function, the module @doc
attribute is empty whereas a keyword list [deprecated: ".."]
would be expected. There seems to be something special in the compiler regarding the @doc
module attribute, because when I change it to @doc2
it works as expected.
Also note the line number annotation in the first definition, this is also inconsistent with other module attributes. I have already been loking in the Module docs but I don’t see anything that tells me that @doc
is special. Help appreciated