Skip to content

Commit 3abb13b

Browse files
committed
Allow use of macros in alias
1 parent 1be67dc commit 3abb13b

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

lib/elixir/lib/kernel/typespec.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -938,15 +938,15 @@ defmodule Kernel.Typespec do
938938

939939
## Helpers
940940

941-
# This is a backport of Macro.expand/2 because we want to expand
941+
# This is a modified backport of Macro.expand/2 because we want to expand
942942
# aliases but we don't them to become compile-time references.
943943
defp expand_remote({:__aliases__, meta, list} = alias, env) do
944944
case :elixir_aliases.expand_or_concat(meta, list, env, true) do
945945
receiver when is_atom(receiver) ->
946946
receiver
947947

948948
[head | tail] ->
949-
case Macro.expand_once(head, env) do
949+
case Macro.expand(head, env) do
950950
head when is_atom(head) ->
951951
:elixir_aliases.concat([head | tail])
952952

lib/elixir/test/elixir/typespec_test.exs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,19 @@ defmodule TypespecTest do
849849
assert [{:atom, _, Keyword}, {:atom, _, :t}, [{:var, _, :value}]] = kw_with_value_args
850850
end
851851

852+
test "@type with macro in alias" do
853+
bytecode =
854+
test_module do
855+
defmacro module() do
856+
quote do: __MODULE__
857+
end
858+
859+
@type my_type :: module().Foo
860+
end
861+
862+
assert [type: {:my_type, {:atom, _, TypespecTest.TypespecSample.Foo}, []}] = types(bytecode)
863+
end
864+
852865
test "@type with a reserved signature" do
853866
assert_raise Kernel.TypespecError,
854867
~r"type required\/1 is a reserved type and it cannot be defined",

0 commit comments

Comments
 (0)