From 5fbb3f27b2f034b5c1fcdf6355700540db4aab3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20B=C3=A4renz?= Date: Wed, 9 Dec 2020 10:45:41 +0100 Subject: [PATCH] Expand `alias __MODULE__` manually. Fixes #27 --- lib/ex_type/custom_env.ex | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/ex_type/custom_env.ex b/lib/ex_type/custom_env.ex index 691d4ef..ec4b054 100644 --- a/lib/ex_type/custom_env.ex +++ b/lib/ex_type/custom_env.ex @@ -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