After some feedback from José, we landed on Macro.Env.lookup_alias_as/2. Link to PR for posterity: https://github.com/elixir-lang/elixir/pull/12507
On Saturday, April 1, 2023 at 12:00:36 PM UTC-4 José Valim wrote: Hi Zach, thanks for the proposal! A PR for "fetch_alias_as" is welcome, we even use private APIs in Kino.VegaLite and friends which we could stop using if this function existed. :) On Sat, Apr 1, 2023 at 5:48 PM Zach Allaun <zach....@gmail.com> wrote: 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-co...@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 <https://groups.google.com/d/msgid/elixir-lang-core/d7bce667-b568-4bfa-a0a4-d03ac24b9eben%40googlegroups.com?utm_medium=email&utm_source=footer> . -- 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/6b032db6-dc91-4263-9a2e-da94c7488681n%40googlegroups.com.