diff --git a/lib/elixir/lib/registry.ex b/lib/elixir/lib/registry.ex index 75a1caddd7..69eb1b9ca9 100644 --- a/lib/elixir/lib/registry.ex +++ b/lib/elixir/lib/registry.ex @@ -534,7 +534,8 @@ defmodule Registry do """ @spec match(registry, key, match_pattern :: atom() | tuple(), guards :: list()) :: [{pid, term}] def match(registry, key, pattern, guards \\ []) when is_atom(registry) and is_list(guards) do - spec = [{{key, {:_, pattern}}, guards, [{:element, 2, :"$_"}]}] + guards = [{:"=:=", {:element, 1, :"$_"}, {:const, key}} | guards] + spec = [{{:_, {:_, pattern}}, guards, [{:element, 2, :"$_"}]}] case key_info!(registry) do {:unique, partitions, key_ets} -> diff --git a/lib/elixir/test/elixir/registry_test.exs b/lib/elixir/test/elixir/registry_test.exs index 58f954a987..1cecf2cd51 100644 --- a/lib/elixir/test/elixir/registry_test.exs +++ b/lib/elixir/test/elixir/registry_test.exs @@ -69,6 +69,10 @@ defmodule RegistryTest do [{self(), value}] assert Registry.match(registry, "hello", {:"$1", :_, :"$1"}) == [{self(), value}] + assert Registry.match(registry, "hello", :_) == + [{self(), value}] + assert Registry.match(registry, :_, :_) == + [] end test "supports guard conditions", %{registry: registry} do