Skip to content

Commit 9560130

Browse files
yuyichaotkelman
authored andcommitted
Fix at-deprecate (#20551)
* Make the `ex` optional argument work for methods definitions too * Use correct function name. Fix #20220 and revert #20538
1 parent ffc86a4 commit 9560130

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

base/deprecated.jl

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
macro deprecate(old,new,ex=true)
2222
meta = Expr(:meta, :noinline)
23+
@gensym oldmtname
2324
if isa(old,Symbol)
2425
oldname = Expr(:quote,old)
2526
newname = Expr(:quote,new)
@@ -28,31 +29,30 @@ macro deprecate(old,new,ex=true)
2829
:(function $(esc(old))(args...)
2930
$meta
3031
depwarn(string($oldname," is deprecated, use ",$newname," instead."),
31-
$oldname)
32+
$oldmtname)
3233
$(esc(new))(args...)
33-
end))
34+
end),
35+
:(const $oldmtname = Core.Typeof($(esc(old))).name.mt.name))
3436
elseif isa(old,Expr) && old.head == :call
3537
remove_linenums!(new)
3638
oldcall = sprint(show_unquoted, old)
3739
newcall = sprint(show_unquoted, new)
3840
oldsym = if isa(old.args[1],Symbol)
39-
old.args[1]
41+
old.args[1]::Symbol
4042
elseif isa(old.args[1],Expr) && old.args[1].head == :curly
41-
old.args[1].args[1]
43+
old.args[1].args[1]::Symbol
4244
else
4345
error("invalid usage of @deprecate")
4446
end
45-
# work around #20220, deprecation for Array repeating over and over
46-
# TODO: remove the special case when 0.6 deprecations are removed
47-
oldname = Expr(:quote, oldsym in (:Array, :SharedArray) ? :Type : oldsym)
4847
Expr(:toplevel,
49-
Expr(:export,esc(oldsym)),
48+
ex ? Expr(:export,esc(oldsym)) : nothing,
5049
:($(esc(old)) = begin
5150
$meta
5251
depwarn(string($oldcall," is deprecated, use ",$newcall," instead."),
53-
$oldname)
52+
$oldmtname)
5453
$(esc(new))
55-
end))
54+
end),
55+
:(const $oldmtname = Core.Typeof($(esc(oldsym))).name.mt.name))
5656
else
5757
error("invalid usage of @deprecate")
5858
end
@@ -1142,7 +1142,6 @@ function partial_linear_indexing_warning(n)
11421142
end
11431143

11441144
# Deprecate Array(T, dims...) in favor of proper type constructors
1145-
# TODO: when removing these, get rid of the special casing in the @deprecate macro up top
11461145
@deprecate Array{T,N}(::Type{T}, d::NTuple{N,Int}) Array{T}(d)
11471146
@deprecate Array{T}(::Type{T}, d::Int...) Array{T}(d...)
11481147
@deprecate Array{T}(::Type{T}, m::Int) Array{T}(m)

0 commit comments

Comments
 (0)