Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expanding macrocalls and blocks in with_kw #155

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Parameters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,)
Expand Down
7 changes: 7 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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