Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct Registry.match/4's typespec of its "pattern" argument #6508

Merged
merged 2 commits into from Aug 27, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/elixir/lib/registry.ex
Expand Up @@ -532,7 +532,7 @@ defmodule Registry do
[{self(), {1, :atom, 1}}, {self(), {2, :atom, 2}}]

"""
@spec match(registry, key, match_pattern :: atom() | tuple(), guards :: list()) :: [{pid, term}]
@spec match(registry, key, match_pattern :: term, guards :: list()) :: [{pid, term}]
def match(registry, key, pattern, guards \\ []) when is_atom(registry) and is_list(guards) do
guards = [{:"=:=", {:element, 1, :"$_"}, {:const, key}} | guards]
spec = [{{:_, {:_, pattern}}, guards, [{:element, 2, :"$_"}]}]
Expand Down
12 changes: 7 additions & 5 deletions lib/elixir/test/elixir/registry_test.exs
Expand Up @@ -59,20 +59,22 @@ defmodule RegistryTest do
end

test "supports match patterns", %{registry: registry} do
value = {1, :atom, 1}
value = {1, :atom, 1, %{a: "a", b: "b"}}
{:ok, _} = Registry.register(registry, "hello", value)
assert Registry.match(registry, "hello", {1, :_, :_}) ==
assert Registry.match(registry, "hello", {1, :_, :_, :_}) ==
[{self(), value}]
assert Registry.match(registry, "hello", {1.0, :_, :_}) ==
assert Registry.match(registry, "hello", {1.0, :_, :_, :_}) ==
[]
assert Registry.match(registry, "hello", {:_, :atom, :_}) ==
assert Registry.match(registry, "hello", {:_, :atom, :_, :_}) ==
[{self(), value}]
assert Registry.match(registry, "hello", {:"$1", :_, :"$1"}) ==
assert Registry.match(registry, "hello", {:"$1", :_, :"$1", :_}) ==
[{self(), value}]
assert Registry.match(registry, "hello", :_) ==
[{self(), value}]
assert Registry.match(registry, :_, :_) ==
[]
assert Registry.match(registry, "hello", {:_, :_, :_, %{b: "b"}}) ==
[{self(), value}]
end

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