Skip to content

Commit

Permalink
Allow use of macros in alias
Browse files Browse the repository at this point in the history
  • Loading branch information
sabiwara committed Jan 9, 2025
1 parent 1be67dc commit 3abb13b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/elixir/lib/kernel/typespec.ex
Original file line number Diff line number Diff line change
Expand Up @@ -938,15 +938,15 @@ defmodule Kernel.Typespec do

## Helpers

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

[head | tail] ->
case Macro.expand_once(head, env) do
case Macro.expand(head, env) do
head when is_atom(head) ->
:elixir_aliases.concat([head | tail])

Expand Down
13 changes: 13 additions & 0 deletions lib/elixir/test/elixir/typespec_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,19 @@ defmodule TypespecTest do
assert [{:atom, _, Keyword}, {:atom, _, :t}, [{:var, _, :value}]] = kw_with_value_args
end

test "@type with macro in alias" do
bytecode =
test_module do
defmacro module() do
quote do: __MODULE__
end

@type my_type :: module().Foo
end

assert [type: {:my_type, {:atom, _, TypespecTest.TypespecSample.Foo}, []}] = types(bytecode)
end

test "@type with a reserved signature" do
assert_raise Kernel.TypespecError,
~r"type required\/1 is a reserved type and it cannot be defined",
Expand Down

0 comments on commit 3abb13b

Please sign in to comment.