Skip to content

Commit 200ba95

Browse files
committed
expanding macrocalls and blocks in with_kw
1 parent 501b47b commit 200ba95

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/Parameters.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,10 @@ function with_kw(typedef, mod::Module, withshow=true)
330330
if typedef.head==:tuple # named-tuple
331331
withshow==false && error("`@with_kw_noshow` not supported for named tuples")
332332
return with_kw_nt(typedef, mod)
333+
elseif typedef.head == :macrocall
334+
return with_kw(macroexpand(mod, typedef), mod, withshow)
335+
elseif typedef.head == :block
336+
return with_kw(typedef.args[2], mod, withshow)
333337
elseif typedef.head != :struct
334338
error("""Only works on type-defs or named tuples.
335339
Make sure to have a space after `@with_kw`, e.g. `@with_kw (a=1,)

test/runtests.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,3 +724,10 @@ end
724724
@test_throws ErrorException global b34 = 1
725725
## this test is dependent on Julia version, leave it:
726726
# @test_warn "WARNING: redefinition of constant b34. This may fail, cause incorrect answers, or produce other errors." global b34 = 4.0
727+
728+
macro structmacro()
729+
return quote struct mystruct; myfield::Int; end end
730+
end
731+
732+
# triggers a with_kw call on :macrocall and :block
733+
@with_kw @structmacro

0 commit comments

Comments
 (0)