diff --git a/src/Parameters.jl b/src/Parameters.jl index 47945ff..319c27a 100644 --- a/src/Parameters.jl +++ b/src/Parameters.jl @@ -330,6 +330,10 @@ function with_kw(typedef, mod::Module, withshow=true) if typedef.head==:tuple # named-tuple withshow==false && error("`@with_kw_noshow` not supported for named tuples") return with_kw_nt(typedef, mod) + elseif typedef.head == :macrocall + return with_kw(macroexpand(mod, typedef), mod, withshow) + elseif typedef.head == :block + return with_kw(typedef.args[2], mod, withshow) elseif typedef.head != :struct error("""Only works on type-defs or named tuples. Make sure to have a space after `@with_kw`, e.g. `@with_kw (a=1,) diff --git a/test/runtests.jl b/test/runtests.jl index eb7a3a2..f072e32 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -724,3 +724,10 @@ end @test_throws ErrorException global b34 = 1 ## this test is dependent on Julia version, leave it: # @test_warn "WARNING: redefinition of constant b34. This may fail, cause incorrect answers, or produce other errors." global b34 = 4.0 + +macro structmacro() + return quote struct mystruct; myfield::Int; end end +end + +# triggers a with_kw call on :macrocall and :block +@with_kw @structmacro