Upon reflection, the change that I'm proposing to Macro.Env.fetch_alias/2 does not make sense. If you have Baz, then it already evaluates to Foo.Bar.
Please ignore that portion of the proposal. :) On Saturday, April 1, 2023 at 11:38:47 AM UTC-4 Zach Allaun wrote: > *Context* > > Since Elixir 1.13, Macro.Env.fetch_alias/2 has existed as a mechanism to > resolve an alias to its fully-qualified name. This has the limitation, > however, that you cannot use the actual alias in the lookup. > > iex> alias Foo.Bar, as: Baz > iex> Macro.Env.fetch_alias(__ENV__, :Baz) > {:ok, Foo.Bar} > iex> Macro.Env.fetch_alias(__ENV__, Baz) > :error > > There is not a mechanism to go the other way without relying on the > private aliases field in a Macro.Env struct. > > *Proposal* > > Introduce a new function, Macro.Env.fetch_aliased_as/2, that is able to > look up the name that a module is aliased as. Additionally, extend the > behavior of both Macro.Env.fetch_aliased_as/2 and Macro.Env.fetch_alias/2 > to accept qualified atoms. > > iex> alias Foo.Bar, as: Baz > Baz > > iex> Macro.Env.fetch_alias(__ENV__, :Baz) > {:ok, Foo.Bar} > iex> Macro.Env.fetch_alias(__ENV__, Baz) > {:ok, Foo.Bar} > iex> Macro.Env.fetch_alias(__ENV__, :Unknown) > :error > > iex> Macro.Env.fetch_aliased_as(__ENV__, :"Foo.Bar") > {:ok, Baz} > iex> Macro.Env.fetch_aliased_as(__ENV__, Foo.Bar} > {:ok, Baz} > iex> Macro.Env.fetch_aliased_as(__ENV__, Foo.Unknown) > :error > > I'll submit a PR shortly for this change, but am happy to wait for any > discussion that might happen here before it's acted on. > -- 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-core+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/d7bce667-b568-4bfa-a0a4-d03ac24b9eben%40googlegroups.com.