Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/elixir/lib/kernel/typespec.ex
Original file line number Diff line number Diff line change
Expand Up @@ -947,8 +947,11 @@ defmodule Kernel.Typespec do

[head | tail] ->
case Macro.expand_once(head, env) do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think then we need to replace this by expand instead of expand_once. Otherwise if you have a macro this macro:

defmacro current_module do
  quote do
    __MODULE__
  end
end

and this typespec:

current_module().Foo.Bar

It will no longer work, as the first expansion will return __MODULE__.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think then we need to replace this by expand instead of expand_once.

Done in 3abb13b

It will no longer work,

Just FYI, I checked and this was an infinite loop as well so technically it did never worked (we were returning the pre-expansion alias as is and kept looping). I agree we should fix it of course.

head when is_atom(head) -> :elixir_aliases.concat([head | tail])
_ -> alias
head when is_atom(head) ->
:elixir_aliases.concat([head | tail])

_ ->
compile_error(env, "unexpected expression in typespec: #{Macro.to_string(alias)}")
end
end
end
Expand Down
14 changes: 11 additions & 3 deletions lib/elixir/test/elixir/typespec_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ defmodule TypespecTest do
@type my_type :: %URI.t(){}
end
end

assert_raise Kernel.TypespecError,
~r"unexpected expression in typespec: t\.Foo",
fn ->
test_module do
@type my_type :: t.Foo
end
end
end

test "invalid function specification" do
Expand Down Expand Up @@ -120,7 +128,7 @@ defmodule TypespecTest do

test "redefined type" do
assert_raise Kernel.TypespecError,
~r"type foo/0 is already defined in .*test/elixir/typespec_test.exs:126",
~r"type foo/0 is already defined in .*test/elixir/typespec_test.exs:134",
fn ->
test_module do
@type foo :: atom
Expand All @@ -129,7 +137,7 @@ defmodule TypespecTest do
end

assert_raise Kernel.TypespecError,
~r"type foo/2 is already defined in .*test/elixir/typespec_test.exs:136",
~r"type foo/2 is already defined in .*test/elixir/typespec_test.exs:144",
fn ->
test_module do
@type foo :: atom
Expand All @@ -139,7 +147,7 @@ defmodule TypespecTest do
end

assert_raise Kernel.TypespecError,
~r"type foo/0 is already defined in .*test/elixir/typespec_test.exs:145",
~r"type foo/0 is already defined in .*test/elixir/typespec_test.exs:153",
fn ->
test_module do
@type foo :: atom
Expand Down
Loading