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

Unable to compare named tuple union type #5131

Closed
straight-shoota opened this issue Oct 16, 2017 · 2 comments
Closed

Unable to compare named tuple union type #5131

straight-shoota opened this issue Oct 16, 2017 · 2 comments

Comments

@straight-shoota
Copy link
Member

Comparing a NamedTuple with a UnionType of NamedTuple types fails because the union type seems to match NamedTuple in NamedTuple#==(other : NamedTuple), but does not respond to keys method used in the macro code of NamedTuple#compare_with_other_named_tuple.

Example:

[{bar: nil}, {foo: nil}] == [{bar: nil}, {foo: nil}]

carc.in

The above code fails with

in /usr/lib/crystal/named_tuple.cr:459: undefined method 'keys' for TypeNode of type (NamedTuple(bar: Nil) | NamedTuple(foo: Nil)) (must be a named tuple type)

    {% if T.keys.sort == U.keys.sort %}

Same result for 0.23.1 and master.

@asterite
Copy link
Member

How did you get a union of named tuples? What's the use case?

@asterite asterite added this to the Next milestone Oct 16, 2017
@straight-shoota
Copy link
Member Author

Thanks for the quick fix =)

My use case was actually experimenting with a way to use named tuples instead of Tuple(Symbol, X) for a list of parser tokens.

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

No branches or pull requests

2 participants