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

Introduce Tuple.element_type and NamedTuple.element_type #12011

Merged

Conversation

HertzDevil
Copy link
Contributor

These macros act as compile-time equivalents of Enumerable.element_type, and encapsulate the typeof(begin; ...; end) pattern found in e.g. #11834 and #12008.

Due to syntax limitations, the line below will not work:

Tuple(Int32, String).element_type(1) # Error: undefined method 'element_type' for Tuple(Int32, String).class

For some reason it doesn't work even on aliases of Tuple instances, so these macros are private for now; the currently use cases do not require this macro to be public or protected. Also note that Enumerable is a module, so Enumerable.element_type is not inherited by Tuple and NamedTuple.

@straight-shoota straight-shoota added this to the 1.5.0 milestone Apr 20, 2022
@straight-shoota straight-shoota merged commit 8bf1ab7 into crystal-lang:master Apr 27, 2022
@HertzDevil HertzDevil deleted the refactor/tuple-element_type branch April 28, 2022 09:09
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants