|
18 | 18 | # the name of the function, which is used to ensure that the deprecation warning |
19 | 19 | # is only printed the first time for each call place. |
20 | 20 |
|
21 | | -macro deprecate(old,new,ex=true) |
| 21 | +macro deprecate(old, new, ex=true) |
22 | 22 | meta = Expr(:meta, :noinline) |
23 | 23 | @gensym oldmtname |
24 | | - if isa(old,Symbol) |
25 | | - oldname = Expr(:quote,old) |
26 | | - newname = Expr(:quote,new) |
| 24 | + if isa(old, Symbol) |
| 25 | + oldname = Expr(:quote, old) |
| 26 | + newname = Expr(:quote, new) |
27 | 27 | Expr(:toplevel, |
28 | | - ex ? Expr(:export,esc(old)) : nothing, |
| 28 | + ex ? Expr(:export, esc(old)) : nothing, |
29 | 29 | :(function $(esc(old))(args...) |
30 | 30 | $meta |
31 | | - depwarn(string($oldname," is deprecated, use ",$newname," instead."), |
| 31 | + depwarn(string($oldname, " is deprecated, use ", $newname, " instead."), |
32 | 32 | $oldmtname) |
33 | 33 | $(esc(new))(args...) |
34 | 34 | end), |
35 | 35 | :(const $oldmtname = Core.Typeof($(esc(old))).name.mt.name)) |
36 | | - elseif isa(old,Expr) && old.head == :call |
| 36 | + elseif isa(old, Expr) && (old.head == :call || old.head == :where) |
37 | 37 | remove_linenums!(new) |
38 | 38 | oldcall = sprint(show_unquoted, old) |
39 | 39 | newcall = sprint(show_unquoted, new) |
40 | | - oldsym = if isa(old.args[1],Symbol) |
41 | | - old.args[1]::Symbol |
42 | | - elseif isa(old.args[1],Expr) && old.args[1].head == :curly |
43 | | - old.args[1].args[1]::Symbol |
| 40 | + # if old.head is a :where, step down one level to the :call to avoid code duplication below |
| 41 | + callexpr = old.head == :call ? old : old.args[1] |
| 42 | + if callexpr.head == :call |
| 43 | + if isa(callexpr.args[1], Symbol) |
| 44 | + oldsym = callexpr.args[1]::Symbol |
| 45 | + elseif isa(callexpr.args[1], Expr) && callexpr.args[1].head == :curly |
| 46 | + oldsym = callexpr.args[1].args[1]::Symbol |
| 47 | + else |
| 48 | + error("invalid usage of @deprecate") |
| 49 | + end |
44 | 50 | else |
45 | 51 | error("invalid usage of @deprecate") |
46 | 52 | end |
47 | 53 | Expr(:toplevel, |
48 | | - ex ? Expr(:export,esc(oldsym)) : nothing, |
| 54 | + ex ? Expr(:export, esc(oldsym)) : nothing, |
49 | 55 | :($(esc(old)) = begin |
50 | 56 | $meta |
51 | | - depwarn(string($oldcall," is deprecated, use ",$newcall," instead."), |
| 57 | + depwarn(string($oldcall, " is deprecated, use ", $newcall, " instead."), |
52 | 58 | $oldmtname) |
53 | 59 | $(esc(new)) |
54 | 60 | end), |
|
0 commit comments