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

Macros: automatically resolve alias in types #4995

merged 1 commit into from
Sep 21, 2017

Macros: automatically resolve alias in types #4995

merged 1 commit into from
Sep 21, 2017


Copy link

Fixes #4301

This makes is so that if T is a (non-recursive) alias type, using T in macros automatically resolved to the aliased type. With this we can now do (for example):

puts "All primitive integers"
{% for type in Int::Primitive.union_types %}
  puts {{type}}
{% end %}

This can greatly simply code. For example here:

{% for type in %w(Int8 Int16 Int32 Int64 UInt8 UInt16 UInt32 UInt64) %}

An alternative implementation would be to add a macro method to solve an alias type. But alias types in regular code can never be reached by the user: trying to use one immediately uses the underlying type. So doing the same thing in macros is consistent. For example:

alias Foo = Int32

There's simply now way to make a program print "Foo" at runtime by using that alias, because trying to use it will solve to Int32.

@asterite asterite merged commit 3ca5428 into crystal-lang:master Sep 21, 2017
@asterite asterite added this to the Next milestone Sep 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

Successfully merging this pull request may close these issues.

No way to use alias of NamedTuple in macros
2 participants