GenServer + defmacro bug ???

32 views
Skip to first unread message

João Bernardo

unread,
Nov 4, 2016, 4:12:40 PM11/4/16
to elixir-lang-core
Hi !

I defined a macro like this:

```
defmodule Test do
  defmacro __using__ do
    quote do
      require Test
      import Test
    end
  end

  defmacro my_macro do
    quote do
      Gernserver.call() # generic server call from other module
    end
  end
end
```

I have this code inside a lib which I am building. When testing this lib in a different application I get a compile error on the file which has the `use Test`.

Error: `exited in: GenServer.call ...` `exit no process` (on the line of the my_macro call, more specifically on the genserver call). As if the genserver was not running, and it is not because it is compile time.

Adding a simple Application.ensure_all_started(:lib_name) to the __using__ macro seems to fix the problem. But then again, at compile time the code shouldn't be running, am I right ? Or is here something I am not seeing ? Maybe I can not use genserver calls on a macro ? Or is it a bug ?

Thanks.

José Valim

unread,
Nov 4, 2016, 4:20:34 PM11/4/16
to elixir-l...@googlegroups.com
You need to provide more information. Possibly a mechanism to reproduce the bug. Otherwise, we will be all at guesses of what went wrong. You are right the code should not be executed at compile time as long as you are calling the GenServer inside a function.

If you are not sure it is an Elixir bug, it is probably better to move the discussion elsewhere, such as Stack Overflow or Elixir Forum.

João Bernardo

unread,
Nov 4, 2016, 4:23:44 PM11/4/16
to elixir-lang-core, jose....@plataformatec.com.br
Yep you're right, I've been at the elixir slack but no one seemed to get an answer. I will post it to Stack Overflow.
Reply all
Reply to author
Forward
0 new messages