Skip to content

Commit

Permalink
added missing deprecation for @pack (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
mauro3 authored Sep 4, 2018
1 parent b25fa15 commit fc521ee
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/Parameters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module Parameters
import Base: @__doc__
import OrderedCollections: OrderedDict

export @with_kw, @with_kw_noshow, type2dict, reconstruct, @unpack, @pack!
export @with_kw, @with_kw_noshow, type2dict, reconstruct, @unpack, @pack!, @pack

## Parser helpers
#################
Expand Down Expand Up @@ -764,18 +764,25 @@ d.c == "HaHa" #true
```
"""
macro pack!(args)
esc(_pack_bang(args))
end

macro pack(args)
Base.depwarn("The macro `@pack` is deprecated, use `@pack!`", Symbol("@pack"))
esc(_pack_bang(args))
end
function _pack_bang(args)
args.head!=:(=) && error("Expression needs to be of form `a = b,c`")
suitecase, items = args.args
items = isa(items, Symbol) ? [items] : items.args
suitecase_instance = gensym()
kd = [:( $Parameters.pack!($suitecase_instance, Val{$(Expr(:quote, key))}(), $key) ) for key in items]
kdblock = Expr(:block, kd...)
expr = quote
return quote
$suitecase_instance = $suitecase # handles if suitecase is not a variable but an expression
$kdblock
($(items...),)
end
esc(expr)
end

# TODO: maybe add @pack_new for packing into a new instance. Could be
Expand Down

0 comments on commit fc521ee

Please sign in to comment.