Skip to content

Commit

Permalink
Make standard match bindings not throw unused warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
zoldar committed Jan 29, 2025
1 parent f51c117 commit 1221960
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion test/support/assert_matches.ex
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ defmodule Plausible.AssertMatches do

{:^, _meta, [pinned]}, acc ->
pinned = Plausible.AssertMatches.Internal.transform_predicate(pinned)
pinned_var = Macro.unique_var(:match, __MODULE__)

pinned_var =
Macro.unique_var(:match, __MODULE__)
|> Macro.update_meta(&Keyword.put(&1, :assert_match, true))

{pinned_var, [{pinned_var, pinned} | acc]}

other, acc ->
Expand All @@ -83,6 +87,19 @@ defmodule Plausible.AssertMatches do
end)
end)

var_pattern =
Macro.postwalk(var_pattern, fn
{name, meta, module} = var when is_atom(name) and is_atom(module) ->
if meta[:assert_match] do
var
else
{:_, [], __MODULE__}
end

other ->
other
end)

predicate_pattern =
quote bind_quoted: [
var_pattern: Macro.escape(var_pattern),
Expand Down

0 comments on commit 1221960

Please sign in to comment.