Aliases of non existent modules

35 views
Skip to first unread message

Jan Ziniewicz

unread,
Mar 1, 2019, 9:08:04 AM3/1/19
to elixir-lang-core

Hi everyone,

Please take a look at this line of code:

alias This.Module.Does.Not.Exist

In my opinion compiler should emit an error or at least warning when trying to alias a non existent module? However, this line is perfectly valid  piece of code.
Asking just out of curiosity, is this a bug or a feature?

Best, Jan

Alexei Sholik

unread,
Mar 1, 2019, 10:12:09 AM3/1/19
to elixir-lang-core
Mix does warn about it when you try to call a function from a non-existent module:

$ mix compile
Compiling 1 file (.ex)
warning: function This.Module.Does.Not.Exist.foo/0 is undefined (module This.Module.Does.Not.Exist is not available)

It does so because `mix xref` runs automatically on each compilation. The base Elixir compiler doesn't perform such checks.

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/3bc43a69-ad37-4323-be65-f7ddac4aaead%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

José Valim

unread,
Mar 1, 2019, 10:22:41 AM3/1/19
to elixir-l...@googlegroups.com
To expand on that, that's because the Elixir compiler compiles everything in parallel, so at compilation time, we don't know what is defined yet.

Furthermore, this is sometimes desired behaviour. For example, when it comes to optional dependencies. Ecto, for instance, can work with both Jason and Poison, so it calls both, but if a dev only has Jason as a dependency, Ecto should still compile.

José Valim
Skype: jv.ptec
Founder and Director of R&D


Jan Ziniewicz

unread,
Mar 1, 2019, 10:50:20 AM3/1/19
to elixir-lang-core
Makes sense. Thank you very much!
Reply all
Reply to author
Forward
0 new messages