Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upRequired private modules don't survive quote blocks #1
Comments
This comment has been minimized.
This comment has been minimized.
The expansions: -file("/vagrant/code/using_private/lib/using_private"
"/good.ex",
1).
-module('Elixir.UsingPrivate.Good').
-compile([no_auto_import]).
-export(['__info__'/1, hello/0]).
-spec '__info__'(attributes | compile | functions |
macros | md5 | module | deprecated) -> any().
'__info__'(module) -> 'Elixir.UsingPrivate.Good';
'__info__'(functions) -> [{hello, 0}];
'__info__'(macros) -> [];
'__info__'(Key = attributes) ->
erlang:get_module_info('Elixir.UsingPrivate.Good', Key);
'__info__'(Key = compile) ->
erlang:get_module_info('Elixir.UsingPrivate.Good', Key);
'__info__'(Key = md5) ->
erlang:get_module_info('Elixir.UsingPrivate.Good', Key);
'__info__'(deprecated) -> [].
hello() -> 'Elixirp.UsingPrivate.Impl':hello(). -file("/vagrant/code/using_private/lib/using_private"
"/bad.ex",
1).
-module('Elixir.UsingPrivate.Bad').
-compile([no_auto_import]).
-export(['__info__'/1, hello/0]).
-spec '__info__'(attributes | compile | functions |
macros | md5 | module | deprecated) -> any().
'__info__'(module) -> 'Elixir.UsingPrivate.Bad';
'__info__'(functions) -> [{hello, 0}];
'__info__'(macros) -> [];
'__info__'(Key = attributes) ->
erlang:get_module_info('Elixir.UsingPrivate.Bad', Key);
'__info__'(Key = compile) ->
erlang:get_module_info('Elixir.UsingPrivate.Bad', Key);
'__info__'(Key = md5) ->
erlang:get_module_info('Elixir.UsingPrivate.Bad', Key);
'__info__'(deprecated) -> [].
hello() -> 'Elixir.Impl':hello(). Looks like the aliasing of |
This comment has been minimized.
This comment has been minimized.
Workaround: defmodule UsingPrivate do
defmacro __using__(_opts) do
quote do
require :"Elixirp.UsingPrivate.Impl", as: Impl
def hello, do: Impl.hello()
end
end
end But as you specifically say,
|
This comment has been minimized.
This comment has been minimized.
I am not quite sure if this is fixable. ;( have you tried using requirep
outside of the quote, right above it, instead of inside?
--
*José Valim*
www.plataformatec.com.br
Skype: jv.ptec
Founder and Director of R&D
|
This comment has been minimized.
This comment has been minimized.
Aha @josevalim! I swore I tried that # `lib/using_private.ex`
defmodule UsingPrivate do
defmacro __using__(_opts) do
quote do
def hello, do: Impl.hello()
end
end
end # `lib/using_private/bad.ex`
defmodule UsingPrivate.Bad do
import Defmodulep
requirep UsingPrivate.Impl, as: Impl
use UsingPrivate
end $ mix compile --force
Compiling 4 files (.ex)
Generated using_private app iex> UsingPrivate.Bad.hello
hello
:ok Works perfectly. I notice that |
This comment has been minimized.
This comment has been minimized.
We would need to make requirep part of Elixir, yeah.
--
*José Valimwww.plataformatec.com.br
<http://www.plataformatec.com.br/>Founder and Director of R&D*
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Minimum example here.
If we define a private module:
And define a quoted block that uses that private module:
And finally use that quoted block in a fresh module
We get a compiler warning:
And an error in iex
The module is not defined!
If we write the same code without the quoted block, though, everything works as expected: