Search code examples
crystal-lang

How to resolve Generics in macros?


macro m(type)
  {% puts type.resolve %}
end

module Foo
  class Bar
  end

  class Baz
    m(Array(Bar))
  end
end

# in temp4.cr:10: undefined macro method 'Generic#resolve'
# 
#     m(Array(Bar))

I need to resolve Array(Bar) so it prints type with full paths (Array(Foo::Bar)). Is there a convenient way of doing so regardless of the type complexity (e.g. Array(Bar, Array(SomeOtherType) | Int32))?


Solution

  • Resolved by this PR: https://github.com/crystal-lang/crystal/pull/6617. Thanks Ary!