mauro3 / Parameters.jl

Types with default field values, keyword constructors and (un-)pack macros
Other
420 stars 31 forks source link

Macroexpansion of @with_kw argument #154

Open jkosata opened 1 year ago

jkosata commented 1 year ago

I am experimenting with macros that define a struct. Here's an MWE of my problem:

using Parameters

macro structmacro()
    return quote struct mystruct; myfield::Int; end end
end

@with_kw @structmacro

gives

ERROR: LoadError: @with_kw only supported for types which have at least one field.

Seems that @with_kw does not expand @structmacro into a struct declaration. The solution is probably analogous to #21

jkosata commented 1 year ago

Turns out expanding :macrocall and :block expressions in with_kw does the trick here. Submitting a pull request as I need this functionality for https://github.com/jkosata/DefaultFields.jl