FluxML / MacroTools.jl

MacroTools provides a library of tools for working with Julia code and expressions.
https://fluxml.ai/MacroTools.jl/stable/
Other
308 stars 77 forks source link

Splitdef errors on anonymous function with a single varargs argument #185

Open julbinb opened 2 years ago

julbinb commented 2 years ago

splitdef fails with an assertion on an anonymous function with a single varargs argument:

julia> splitdef(Meta.parse(" (args...) -> 0 "))
ERROR: ArgumentError: Not a function definition: :(args...->begin
          #= none:1 =#
          0
      end)
Stacktrace:
 [1] splitdef(fdef::Expr)
   @ MacroTools ~/.julia/packages/MacroTools/PP9IQ/src/utils.jl:317

Either adding another argument or using the long form of the definition is fine:

julia> splitdef(Meta.parse(" (x, args...) -> 0 "))
Dict{Symbol, Any} with 4 entries:
  :args        => Any[:x, :(args...)]
  :body        => quote…
  :kwargs      => Any[]
  :whereparams => ()

julia> splitdef(Meta.parse(" function f(args...) 0 end "))
Dict{Symbol, Any} with 5 entries:
  :name        => :f
  :args        => Any[:(args...)]
  :kwargs      => Any[]
  :body        => quote…
  :whereparams => ()
cstjean commented 2 years ago

PR welcome!