Skip to content

Commit

Permalink
Expand alias __MODULE__ manually. Fixes gyson#27
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel Bärenz committed Dec 9, 2020
1 parent 57daac5 commit 5fbb3f2
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/ex_type/custom_env.ex
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ defmodule ExType.CustomEnv do
defmacro defmodule(alias, do: block) do
{:__aliases__, meta, tokens} = alias

# Manually expand `alias __MODULE__`, see https://github.com/gyson/ex_type/issues/27
block = block
|> Macro.prewalk(fn
{:alias, meta_alias, [{:__MODULE__, meta_module, nil}]} -> {:alias, meta_alias, [{:__aliases__, meta_module, tokens}]}
token -> token
end)

# Don't move nested modules into custom env (https://github.com/gyson/ex_type/issues/23)
env = __CALLER__
new_alias_prefix = case env.module do
Expand Down

0 comments on commit 5fbb3f2

Please sign in to comment.