-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
No way to use alias of NamedTuple in macros #4301
Comments
The question is whether we want to remove the alias automatically here, or with an explicit operation. |
alias TT = {a: Int32, b: Char}
{% puts TT.class_name %} Says it's a alias TT = {a: Int32, b: Char}
{% puts TT.alias?.keys %} # => a, b |
Either methods are suitable, but neither work now. There is now Alias type in Macro module. |
I'd say remove the alias automatically so alias TT = {a: Int32, b: Char}
# type manipulation
{% puts TT.class_name %} # => NamedTuple
{% puts TT.keys %} # => [a, b]
# alias?
{% puts TT.alias? %} # => AliasType (or something similar)
{% puts TT.alias?.name %} # => TT |
Another case is union types: alias TT = Int32 | String
{% puts TT.union? %} #=> false
{% puts TT.union_types %} #=> undefined method 'union_types' for TypeNode of type TT (must be a union type) |
I'm in favour of explicit operation; |
crystal -v
Crystal 0.21.1 (2017-03-14) LLVM 4.0.0
Generate errors:
But TT is exactly the NamedTuple (the alias of it). Tried a lot of combinations but nothing works - I can't access info about NamedTuple type after its declaration.
The text was updated successfully, but these errors were encountered: