Skip to content
Merged
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
16 changes: 11 additions & 5 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,20 @@ macro deprecate(old,new,ex=true)
$(esc(new))(args...)
end),
:(const $oldmtname = Core.Typeof($(esc(old))).name.mt.name))
elseif isa(old,Expr) && old.head == :call
elseif isa(old, Expr) && (old.head == :call || old.head == :where)
remove_linenums!(new)
oldcall = sprint(show_unquoted, old)
newcall = sprint(show_unquoted, new)
oldsym = if isa(old.args[1],Symbol)
old.args[1]::Symbol
elseif isa(old.args[1],Expr) && old.args[1].head == :curly
old.args[1].args[1]::Symbol
# if old.head is a :where, step down one level to the :call to avoid code duplication below
callexpr = old.head == :call ? old : old.args[1]
if callexpr.head == :call
if isa(callexpr.args[1], Symbol)
oldsym = callexpr.args[1]::Symbol
elseif isa(callexpr.args[1], Expr) && callexpr.args[1].head == :curly
oldsym = callexpr.args[1].args[1]::Symbol
else
error("invalid usage of @deprecate")
end
else
error("invalid usage of @deprecate")
end
Expand Down
41 changes: 41 additions & 0 deletions test/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -701,3 +701,44 @@ end
@test hton(0x102030405060708) == 0x807060504030201
@test ltoh(0x102030405060708) == 0x102030405060708
@test htol(0x102030405060708) == 0x102030405060708

module DeprecationTests # to test @deprecate
f() = true

# test the Symbol path of @deprecate
@deprecate f1 f
@deprecate f2 f false # test that f2 is not exported

# test the Expr path of @deprecate
@deprecate f3() f()
@deprecate f4() f() false # test that f4 is not exported
@deprecate f5(x::T) where T f()

# test deprecation of a constructor
struct A{T} end
@deprecate A{T}(x::S) where {T, S} f()
end # module

@testset "@deprecate" begin
using .DeprecationTests
# enable when issue #22043 is fixed
# @test @test_warn "f1 is deprecated, use f instead." f1()
# @test @test_nowarn f1()

# @test_throws UndefVarError f2() # not exported
# @test @test_warn "f2 is deprecated, use f instead." DeprecationTests.f2()
# @test @test_nowarn DeprecationTests.f2()

# @test @test_warn "f3() is deprecated, use f() instead." f3()
# @test @test_nowarn f3()

# @test_throws UndefVarError f4() # not exported
# @test @test_warn "f4() is deprecated, use f() instead." DeprecationTests.f4()
# @test @test_nowarn DeprecationTests.f4()

# @test @test_warn "f5(x::T) where T is deprecated, use f() instead." f5(1)
# @test @test_nowarn f5(1)

# @test @test_warn "A{T}(x::S) where {T, S} is deprecated, use f() instead." A{Int}(1.)
# @test @test_nowarn A{Int}(1.)
end