Skip to content

Commit 36069cb

Browse files
author
José Valim
committed
Ensure Registry.match/4 works with :_ as key
1 parent 5f735de commit 36069cb

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

lib/elixir/lib/registry.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,8 @@ defmodule Registry do
534534
"""
535535
@spec match(registry, key, match_pattern :: atom() | tuple(), guards :: list()) :: [{pid, term}]
536536
def match(registry, key, pattern, guards \\ []) when is_atom(registry) and is_list(guards) do
537-
spec = [{{key, {:_, pattern}}, guards, [{:element, 2, :"$_"}]}]
537+
guards = [{:"=:=", {:element, 1, :"$_"}, {:const, key}} | guards]
538+
spec = [{{:_, {:_, pattern}}, guards, [{:element, 2, :"$_"}]}]
538539

539540
case key_info!(registry) do
540541
{:unique, partitions, key_ets} ->

lib/elixir/test/elixir/registry_test.exs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ defmodule RegistryTest do
6969
[{self(), value}]
7070
assert Registry.match(registry, "hello", {:"$1", :_, :"$1"}) ==
7171
[{self(), value}]
72+
assert Registry.match(registry, "hello", :_) ==
73+
[{self(), value}]
74+
assert Registry.match(registry, :_, :_) ==
75+
[]
7276
end
7377

7478
test "supports guard conditions", %{registry: registry} do

0 commit comments

Comments
 (0)