Skip to content

Commit

Permalink
Do not consider remote typespecs as a compile-time dependency (#5093)
Browse files Browse the repository at this point in the history
Signed-off-by: José Valim <jose.valim@plataformatec.com.br>
  • Loading branch information
ericentin authored and José Valim committed Aug 4, 2016
1 parent 8a22621 commit a51c1be
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/elixir/lib/kernel/typespec.ex
Expand Up @@ -777,6 +777,8 @@ defmodule Kernel.Typespec do
end

defp typespec({:%, _, [name, {:%{}, meta, fields}]}, vars, caller) do
# We cannot set a function name to avoid tracking
# as a compile time dependency, because for structs it actually is one.
module = Macro.expand(name, caller)

struct =
Expand Down Expand Up @@ -813,6 +815,8 @@ defmodule Kernel.Typespec do
end

defp typespec({:record, meta, [atom, fields]}, vars, caller) do
# We cannot set a function name to avoid tracking
# as a compile time dependency because for records it actually is one.
case Macro.expand({atom, [], [{atom, [], []}]}, caller) do
keyword when is_list(keyword) ->
types =
Expand Down Expand Up @@ -883,7 +887,9 @@ defmodule Kernel.Typespec do

# Handle remote calls
defp typespec({{:., meta, [remote, name]}, _, args} = orig, vars, caller) do
remote = Macro.expand remote, caller
# We set a function name to avoid tracking
# aliases in typespecs as compile time dependencies.
remote = Macro.expand remote, %{caller | function: {:typespec, 0}}
unless is_atom(remote) do
compile_error(caller, "invalid remote in typespec: #{Macro.to_string(orig)}")
end
Expand Down
24 changes: 24 additions & 0 deletions lib/mix/test/mix/tasks/compile.elixir_test.exs
Expand Up @@ -231,4 +231,28 @@ defmodule Mix.Tasks.Compile.ElixirTest do
assert_received {:mix_shell, :info, ["Compiled lib/a.ex"]}
end
end

test "does not treat remote typespecs as compile time dependencies" do
in_fixture "no_mixfile", fn ->
File.write!("lib/b.ex", """
defmodule B do
@type t :: A.t
end
""")

assert Mix.Tasks.Compile.Elixir.run(["--verbose"]) == :ok
assert_received {:mix_shell, :info, ["Compiled lib/a.ex"]}
assert_received {:mix_shell, :info, ["Compiled lib/b.ex"]}

Mix.shell.flush
purge [A, B]

future = {{2020, 1, 1}, {0, 0, 0}}
File.touch!("lib/a.ex", future)
Mix.Tasks.Compile.Elixir.run ["--verbose"]

assert_received {:mix_shell, :info, ["Compiled lib/a.ex"]}
refute_received {:mix_shell, :info, ["Compiled lib/b.ex"]}
end
end
end

0 comments on commit a51c1be

Please sign in to comment.