Skip to content

Commit

Permalink
Drop compat code for Some from #435 and #563
Browse files Browse the repository at this point in the history
But only mark `notnothing` for deprecation.
  • Loading branch information
martinholters committed Oct 4, 2019
1 parent a8c0a75 commit 9c6ae72
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 51 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ Currently, the `@compat` macro supports the following syntaxes:
* `@compat finalizer(func, obj)` with the finalizer to run as the first argument and the object to be finalized
as the second ([#24605]).

* `Some{T}` wraps `T` to signify that a result of `T<:Void` is expected ([#23642]).

* `replace` accepts a pair of pattern and replacement, with the number of replacements as
a keyword argument ([#25165]).

Expand Down
35 changes: 1 addition & 34 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ module Unicode
using Unicode
import Unicode: isassigned, normalize # not exported from Unicode module due to conflicts
end
import Base: notnothing


include("compatmacro.jl")
Expand All @@ -67,40 +68,6 @@ end
end
end



@static if !isdefined(Base, :Some)
import Base: promote_rule, convert
struct Some{T}
value::T
end
promote_rule(::Type{Some{T}}, ::Type{Some{S}}) where {T,S<:T} = Some{T}
promote_rule(::Type{Some{T}}, ::Type{Nothing}) where {T} = Union{Some{T}, Nothing}
convert(::Type{Some{T}}, x::Some) where {T} = Some{T}(convert(T, x.value))
convert(::Type{Union{Some{T}, Nothing}}, x::Some) where {T} = convert(Some{T}, x)

convert(::Type{Union{T, Nothing}}, x::Any) where {T} = convert(T, x)
convert(::Type{Nothing}, x::Any) = throw(MethodError(convert, (Nothing, x)))
convert(::Type{Nothing}, x::Nothing) = nothing

# Note: this is the definition of coalasce prior to 0.7.0-DEV.5278; kept to avoid
# breakage in packages already using it
coalesce(x::Any) = x
coalesce(x::Some) = x.value
coalesce(x::Nothing) = nothing
#coalesce(x::Missing) = missing
coalesce(x::Any, y...) = x
coalesce(x::Some, y...) = x.value
coalesce(x::Nothing, y...) = coalesce(y...)
#coalesce(x::Union{Nothing, Missing}, y...) = coalesce(y...)

notnothing(x::Any) = x
notnothing(::Nothing) = throw(ArgumentError("nothing passed to notnothing"))
export Some, coalesce
else
import Base: notnothing
end

# 0.7.0-DEV.3309
@static if VERSION < v"0.7.0-DEV.3309"
const IteratorSize = Base.iteratorsize
Expand Down
11 changes: 11 additions & 0 deletions test/old.jl
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ module Test25021
@test Compat.Unicode.normalize("\t\r", stripcc=true) == " "
end

# 0.7.0-DEV.3017
@test Compat.notnothing(1) == 1
@test_throws ArgumentError Compat.notnothing(nothing)


# tests of removed functionality (i.e. justs tests Base)

Expand Down Expand Up @@ -581,3 +585,10 @@ end
# 0.7.0-DEV.3137
@test Nothing === (isdefined(Base, :Nothing) ? Base.Nothing : Base.Void)
@test Nothing === Cvoid

# 0.7.0-DEV.3017
@test isa(Some(1), Some{Int})
@test convert(Some{Float64}, Some(1)) == Some(1.0)
@test convert(Nothing, nothing) == nothing
@test_throws MethodError convert(Nothing, 1)
@test Some(nothing) != nothing
15 changes: 0 additions & 15 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,6 @@ let A = [1]
@test x == 1
end

# 0.7.0-DEV.3017
@test isa(Some(1), Some{Int})
@test convert(Some{Float64}, Some(1)) == Some(1.0)
@test convert(Nothing, nothing) == nothing
@test_throws MethodError convert(Nothing, 1)
@test Some(nothing) != nothing
if VERSION < v"0.7.0-DEV.5278"
# coalesce has changed; old behavior kept and tested to avoid accidental breakage
@test coalesce(Some(1)) == 1
@test coalesce(nothing) == nothing
@test coalesce(nothing, Some(1), Some(2)) == 1
end
@test Compat.notnothing(1) == 1
@test_throws ArgumentError Compat.notnothing(nothing)

# 0.7.0-DEV.3309
let v = [1, 2, 3]
@test Compat.IteratorSize(v) isa Base.HasShape
Expand Down

0 comments on commit 9c6ae72

Please sign in to comment.