This test generates warnings about unused variable found.
defmodule UnusedTest do
use ExUnit.Case
def fun, do: %{}
test "unused warning repro" do
found = fun()
assert match?(found, %{})
end
end
warning: variable "found" is unused
test/projections/unused_test.exs:9
warning: variable "found" is unused
test/projections/unused_test.exs:10
No warning, as the variable is actually used in assert's match.
The warning is correct. The first argument of match? is a pattern. A variable used in pattern matches any value. Your test is exactly the same as:
test "unused warning repro" do
found = fun()
assert match?(x, %{})
end
Most probably you wanted:
test "unused warning repro" do
found = fun()
assert match?(^found, %{})
end
Gotcha. Makes sense. Thanks!
Most helpful comment
The warning is correct. The first argument of
match?is a pattern. A variable used in pattern matches any value. Your test is exactly the same as:Most probably you wanted: