Skip to content

Commit a51c1be

Browse files
ericentinJosé Valim
authored andcommitted
Do not consider remote typespecs as a compile-time dependency (#5093)
Signed-off-by: José Valim <jose.valim@plataformatec.com.br>
1 parent 8a22621 commit a51c1be

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

lib/elixir/lib/kernel/typespec.ex

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,8 @@ defmodule Kernel.Typespec do
777777
end
778778

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

782784
struct =
@@ -813,6 +815,8 @@ defmodule Kernel.Typespec do
813815
end
814816

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

884888
# Handle remote calls
885889
defp typespec({{:., meta, [remote, name]}, _, args} = orig, vars, caller) do
886-
remote = Macro.expand remote, caller
890+
# We set a function name to avoid tracking
891+
# aliases in typespecs as compile time dependencies.
892+
remote = Macro.expand remote, %{caller | function: {:typespec, 0}}
887893
unless is_atom(remote) do
888894
compile_error(caller, "invalid remote in typespec: #{Macro.to_string(orig)}")
889895
end

lib/mix/test/mix/tasks/compile.elixir_test.exs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,4 +231,28 @@ defmodule Mix.Tasks.Compile.ElixirTest do
231231
assert_received {:mix_shell, :info, ["Compiled lib/a.ex"]}
232232
end
233233
end
234+
235+
test "does not treat remote typespecs as compile time dependencies" do
236+
in_fixture "no_mixfile", fn ->
237+
File.write!("lib/b.ex", """
238+
defmodule B do
239+
@type t :: A.t
240+
end
241+
""")
242+
243+
assert Mix.Tasks.Compile.Elixir.run(["--verbose"]) == :ok
244+
assert_received {:mix_shell, :info, ["Compiled lib/a.ex"]}
245+
assert_received {:mix_shell, :info, ["Compiled lib/b.ex"]}
246+
247+
Mix.shell.flush
248+
purge [A, B]
249+
250+
future = {{2020, 1, 1}, {0, 0, 0}}
251+
File.touch!("lib/a.ex", future)
252+
Mix.Tasks.Compile.Elixir.run ["--verbose"]
253+
254+
assert_received {:mix_shell, :info, ["Compiled lib/a.ex"]}
255+
refute_received {:mix_shell, :info, ["Compiled lib/b.ex"]}
256+
end
257+
end
234258
end

0 commit comments

Comments
 (0)