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

Registry.register/3 and Registry.match/4 - type of value? #6507

Closed
fredwu opened this Issue Aug 25, 2017 · 2 comments

Comments

Projects
None yet
3 participants
@fredwu
Copy link
Contributor

fredwu commented Aug 25, 2017

Hi,

I've noticed a potential discrepancy in how the type of value is enforced in Registry.register/3 and Registry.match/4, not sure if it's by design as I could be misunderstanding the intended use cases.

According to their typespecs, the value argument in Registry.register/3 is of type term, and the pattern argument (which pattern matches the value) in Registry.match/4 is of type atom() | tuple().

Initially in my code, I used Registry to register a value that is a map. And when using Registry.match/4, I successfully matched the records also using a map as the pattern.

Only when I ran dialyzer did I notice that using map as the pattern is invalid.

So my question is: should a map be allowed as a type of pattern in Registry.match/4? If not, what would be the reason?

I find that for now I'd have to put the map inside a tuple, to satisfy the Dialyzer check.

@benwilson512

This comment has been minimized.

Copy link
Contributor

benwilson512 commented Aug 25, 2017

Per our conversation on slack, the issue is that the typespec for match/4 seems to indicate that the match arg has to be a full match spec pattern but, because that arg is wrapped in match spec here https://github.com/elixir-lang/elixir/blob/master/lib/elixir/lib/registry.ex#L538 that isn't actually correct.

It seems the right typespec should really be just term.

@josevalim

This comment has been minimized.

Copy link
Member

josevalim commented Aug 25, 2017

Sweet, closed in favor of the PR.

@josevalim josevalim closed this Aug 25, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment