I need a method that gets one argument, potentially of union type, that should distinguish with the help of a macro to allow for an extra block per possible single type.
The problem is that the code below doesn’t work anymore with inheritance, since it generates types in the code like Base(Int32|String)+
, i.e. with a +
at the end - and the compiler chokes.
There’s probably an easy way to fix this, right?
Thanks a lot - again!
class Base(T)
end
class Child(T) < Base(T)
end
def m(a : T) forall T
{% for name in T.union_types %}
a.is_a?({{name.id}}) # gets Error: a.is_a?(Base(Int32 | String)+)
{% end %}
end
a = [Base(Int32|String).new]
m(a[0])