Skip to content

Commit

Permalink
Use Collectable instead of Inspect to avoid accidental protocol loading
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Jan 21, 2025
1 parent ba945e9 commit b077989
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/mix/test/mix/tasks/compile.elixir_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1861,24 +1861,24 @@ defmodule Mix.Tasks.Compile.ElixirTest do
defstruct []
end
defimpl Inspect, for: A do
def inspect(_, _), do: "sample"
defimpl Collectable, for: A do
def into(_), do: fn _, _ -> raise "oops" end
end
""")

Mix.Project.push(MixTest.Case.Sample)
assert Mix.Tasks.Compile.run([]) == {:ok, []}
assert inspect(struct(A, [])) == "sample"
assert is_function(Collectable.into(struct(A, [])), 2)

purge([A, B, Inspect.A])
purge([A, B, Collectable.A])
Mix.Task.clear()

assert capture_io(:stderr, fn ->
{:ok, [_]} = Mix.Tasks.Compile.run(["--force"])
end) =~
"the Inspect protocol has already been consolidated"
"the Collectable protocol has already been consolidated"

purge([A, B, Inspect.A])
purge([A, B, Collectable.A])
Mix.Task.clear()
consolidation = Mix.Project.consolidation_path()
args = ["--force", "--purge-consolidation-path-if-stale", consolidation]
Expand Down

0 comments on commit b077989

Please sign in to comment.