You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The original idea was to correctly wrap a method, and generate a new method with the exact same signature. But there doesn't seem to be a way without using a lot of boilerplate like:
macrowrap(def_node)
{% splat_no = def_node.splat_index %}
def{{def_node.name }}_wrapped(
{%for arg, i in def_node.args %}
{%if i == splat_no %}*{%end%}{{ arg }},
{%end%}
{%if double_splat = def_node.double_splat %}
**{{ double_splat }},
{%end%}
{%if block_arg = def_node.block_arg %}
&{{ block_arg }}
{%end%}
)
# wrapper content!endend
wrap deffoo(a : String, *rest : Bool, named : String)
end
wrap defbar(a : String, *, named : String, **kwargs)
end
wrap defbaz(arg : Bool, **kwargs, &block : String->)
end
It feels overkill to do that just to wrap a method..
It would be nice to have a SplatArg & DoubleSplatArg (and BlockArg?) in the array from def_node.args, that would have the correct to_s for their kind. This way we would only need to do *def_node.args to replicate the def_node's signature.
Crystal::Macro::Def#args
is supposed to list all arguments, but if you include a rest character it only shows up as an empty string.Example: https://carc.in/#/r/3m9b
The text was updated successfully, but these errors were encountered: