arjan

arjan

Catching @doc deprecated: "..." annotations

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 :slight_smile:

Marked As Solved

Eiji

Eiji

Unfortunately it would be possible not sooner than in Elixir version 2.x, see: Provide an API to access documentation metadata at compile time · Issue #8095 · elixir-lang/elixir · GitHub

Also Liked

LostKobrakai

LostKobrakai

Yeah @doc deprecated: … is used for soft deprecation @deprecated is hard deprecation integrated with the compiler.

dr_theuns

dr_theuns

I would expect the keyword list approach to work because it’s also used this way in the stdlib. For example, from docs_test.exs:

@doc "Callback doc"
@doc since: "1.2.3", color: :red, deprecated: "use baz/2 instead"
@doc color: :blue, stable: true
@callback foo(any) :: any

and

@doc deprecated: "Use Logger.delete_process_level(pid) instead"

Where Next?

Popular in Questions Top

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
nobody
How to bind a phoenix app to a specific ip address? could not find anything about that, nowhere, unfortunately, but for me this is qui...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
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
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New

Other popular topics Top

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
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30840 112
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
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
nobody
Hi! In PHP: $SERVER['SERVERADDR'] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement