Skip to content

Commit

Permalink
Merge pull request #362 from JuliaLang/fw/depwarn
Browse files Browse the repository at this point in the history
Fix deprecation warnings in source
  • Loading branch information
TotalVerb committed May 18, 2017
2 parents e19f918 + 9ecd444 commit c38d6cd
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 23 deletions.
10 changes: 10 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,7 @@ if !isdefined(Base, :normalize)
end

if !isdefined(Base, :AsyncCondition)
include_string("""
type AsyncCondition
cond::Condition
handle::Ptr{Void}
Expand Down Expand Up @@ -844,6 +845,7 @@ if !isdefined(Base, :AsyncCondition)
this
end
end
""")

Base.wait(c::AsyncCondition) = wait(c.cond)
else
Expand Down Expand Up @@ -1272,9 +1274,11 @@ if VERSION < v"0.6.0-dev.1024"

# julia #14805
if VERSION < v"0.5.0-dev+3256"
include_string("""
immutable Flatten{I}
it::I
end
""")

flatten(itr) = Flatten(itr)

Expand Down Expand Up @@ -1318,10 +1322,12 @@ if VERSION < v"0.6.0-dev.1024"
# Product -- cartesian product of iterators
@compat abstract type AbstractProdIterator end

include_string("""
immutable Prod2{I1, I2} <: AbstractProdIterator
a::I1
b::I2
end
""")

product(a) = Zip1(a)
product(a, b) = Prod2(a, b)
Expand Down Expand Up @@ -1353,10 +1359,12 @@ if VERSION < v"0.6.0-dev.1024"
@inline next(p::Prod2, st) = prod_next(p, st)
@inline done(p::AbstractProdIterator, st) = st[4]

include_string("""
immutable Prod{I1, I2<:AbstractProdIterator} <: AbstractProdIterator
a::I1
b::I2
end
""")

product(a, b, c...) = Prod(a, product(b, c...))
eltype{I1,I2}(::Type{Prod{I1,I2}}) = tuple_type_cons(eltype(I1), eltype(I2))
Expand All @@ -1373,10 +1381,12 @@ if VERSION < v"0.6.0-dev.1024"
if VERSION < v"0.5.0-dev+3510"
partition{T}(c::T, n::Int) = PartitionIterator{T}(c, n)

include_string("""
type PartitionIterator{T}
c::T
n::Int
end
""")

eltype{T}(::Type{PartitionIterator{T}}) = Vector{eltype(T)}

Expand Down
61 changes: 38 additions & 23 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,29 @@ using Base.Test
v = 1
@test_throws AssertionError @assert(v < 1)

type TestCustomShowType end
eval(Expr(:type, true, :TestCustomShowType, quote end))
@compat function show(io::IO, ::MIME"text/plain", ::TestCustomShowType)
print(io, "MyTestCustomShowType")
end
myio = IOBuffer()
display(TextDisplay(myio), MIME"text/plain"(), TestCustomShowType())
@test @compat String(myio) == "MyTestCustomShowType"

type TestCustomShowType2 end
eval(Expr(:type, true, :TestCustomShowType2, quote end))
@compat Base.show(io::IO, ::MIME"text/plain", ::TestCustomShowType2) = print(io, "MyTestCustomShowType2")
myio = IOBuffer()
display(TextDisplay(myio), MIME"text/plain"(), TestCustomShowType2())
@test @compat String(myio) == "MyTestCustomShowType2"

type TestCustomShowType3 end
eval(Expr(:type, true, :TestCustomShowType3, quote end))
@compat show(io::IO, ::TestCustomShowType3) = print(io, "2-Argument-show")
myio = IOBuffer()
display(TextDisplay(myio), TestCustomShowType3())
@test @compat String(myio) == "2-Argument-show"

immutable ParameterizedShowType{T}
eval(Expr(:type, false, :(ParameterizedShowType{T}), quote
_::T
end
end))
myio = IOBuffer()
@compat show{T}(io::IO, ::MIME"text/html", ::ParameterizedShowType{T}) =
print(io, "<code>::", T, "</code>")
Expand Down Expand Up @@ -202,10 +202,10 @@ let convert_funcs_and_types =
@test c.im == 2
end

type Test3609
eval(Expr(:type, true, :Test3609, quote
a
b
end
end))

if VERSION < v"0.4.0-dev+3609"
let v = Test3609(1,2)
Expand Down Expand Up @@ -249,7 +249,7 @@ for x in [:RTLD_LOCAL,:RTLD_GLOBAL,:find_library,:dlsym,:RTLD_LAZY,:RTLD_NODELET
end

# Test unsafe_convert
type Au_c; end
eval(Expr(:type, true, :Au_c, quote end))
x = "abc"
@test @compat String(unsafe_string(Compat.unsafe_convert(Ptr{UInt8}, x))) == x
Compat.unsafe_convert(::Ptr{Au_c}, x) = x
Expand Down Expand Up @@ -868,13 +868,13 @@ module CallTest

using Base.Test, Compat

immutable A
eval(Expr(:type, false, :A, quote
a
end
end))

immutable B{T}
eval(Expr(:type, false, :(B{T}), quote
b::T
end
end))

if VERSION >= v"0.4"
@compat (::Type{A})() = A(1)
Expand Down Expand Up @@ -1585,8 +1585,14 @@ end

# julia#20006
@compat abstract type AbstractFoo20006 end
immutable ConcreteFoo20006{T<:Int} <: AbstractFoo20006 end
immutable ConcreteFoo20006N{T<:Int,N} <: AbstractFoo20006 end
eval(Expr(
:type, false,
Expr(:(<:), :(ConcreteFoo20006{T<:Int}), :AbstractFoo20006),
quote end))
eval(Expr(
:type, false,
Expr(:(<:), :(ConcreteFoo20006N{T<:Int,N}), :AbstractFoo20006),
quote end))
@compat ConcreteFoo200061{T<:Int} = ConcreteFoo20006N{T,1}
@test Compat.TypeUtils.isabstract(AbstractFoo20006)
@test !Compat.TypeUtils.isabstract(ConcreteFoo20006)
Expand Down Expand Up @@ -1757,12 +1763,18 @@ f20500_2() = A20500_2

module CompatArray
using Compat
immutable CartesianArray{T,N} <: AbstractArray{T,N}
parent::Array{T,N}
end
immutable LinearArray{T,N} <: AbstractArray{T,N}
parent::Array{T,N}
end
eval(Expr(
:type, false,
Expr(:(<:), :(CartesianArray{T,N}), :(AbstractArray{T,N})),
quote
parent::Array{T,N}
end))
eval(Expr(
:type, false,
Expr(:(<:), :(LinearArray{T,N}), :(AbstractArray{T,N})),
quote
parent::Array{T,N}
end))
@compat Base.IndexStyle(::Type{<:LinearArray}) = IndexLinear()
end
@test IndexStyle(Array{Float32,2}) === IndexLinear()
Expand Down Expand Up @@ -1853,9 +1865,12 @@ end
# PR 21378
let
# https://en.wikipedia.org/wiki/Swatch_Internet_Time
immutable Beat <: Dates.Period
value::Int64
end
eval(Expr(
:type, false,
Expr(:(<:), :Beat, :(Dates.Period)),
quote
value::Int64
end))

Dates.value(b::Beat) = b.value
Dates.toms(b::Beat) = Dates.value(b) * 86400
Expand Down

0 comments on commit c38d6cd

Please sign in to comment.