Skip to content

Commit e56cf34

Browse files
committed
fix at-deprecate with where syntax
1 parent 41b8377 commit e56cf34

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

base/deprecated.jl

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,37 +18,43 @@
1818
# the name of the function, which is used to ensure that the deprecation warning
1919
# is only printed the first time for each call place.
2020

21-
macro deprecate(old,new,ex=true)
21+
macro deprecate(old, new, ex=true)
2222
meta = Expr(:meta, :noinline)
2323
@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)
2727
Expr(:toplevel,
28-
ex ? Expr(:export,esc(old)) : nothing,
28+
ex ? Expr(:export, esc(old)) : nothing,
2929
:(function $(esc(old))(args...)
3030
$meta
31-
depwarn(string($oldname," is deprecated, use ",$newname," instead."),
31+
depwarn(string($oldname, " is deprecated, use ", $newname, " instead."),
3232
$oldmtname)
3333
$(esc(new))(args...)
3434
end),
3535
:(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)
3737
remove_linenums!(new)
3838
oldcall = sprint(show_unquoted, old)
3939
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
4450
else
4551
error("invalid usage of @deprecate")
4652
end
4753
Expr(:toplevel,
48-
ex ? Expr(:export,esc(oldsym)) : nothing,
54+
ex ? Expr(:export, esc(oldsym)) : nothing,
4955
:($(esc(old)) = begin
5056
$meta
51-
depwarn(string($oldcall," is deprecated, use ",$newcall," instead."),
57+
depwarn(string($oldcall, " is deprecated, use ", $newcall, " instead."),
5258
$oldmtname)
5359
$(esc(new))
5460
end),

0 commit comments

Comments
 (0)