honungsburk

honungsburk

Check that a parameter is a typespec inside a macro?

As the title says: is it possible to verify that a parameter to a macro is a typespec? As I understand it, a macro receives the ASTs as parameters and Elixir does not know anything about typespecs they only have meaning to Dialyzer. In my mental model I guess that Dialyzer analyses the AST directly. Is this a correct understanding?

Most Liked

sodapopcan

sodapopcan

Typespecs are only understood by a handful of module attributes defined here, so these attriutes are working purely in the context of typespecs. For example, you can’t call String.t() anywhere else. Module attributes are just using the @/1 macro so that is what you would be looking for in AST. I can’t speak exactly to how Dialyzer is implemented but that if you are looking for specs for your own purposes then you’d be looking for {:@, _, [{:spec, _, [...]} etc while walking the AST.

Where Next?

Popular in Questions Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
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
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
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
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
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
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New

Other popular topics Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
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
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New

We're in Beta

About us Mission Statement