From f93afea5a73fa4c62c6f22dfb79202e836863af0 Mon Sep 17 00:00:00 2001 From: Martin Holters Date: Fri, 4 Oct 2019 21:56:11 +0200 Subject: [PATCH] Drop compat code for `Some` from #435 and #563 But only mark `notnothing` for deprecation. --- README.md | 2 -- src/Compat.jl | 35 +---------------------------------- test/old.jl | 11 +++++++++++ test/runtests.jl | 15 --------------- 4 files changed, 12 insertions(+), 51 deletions(-) diff --git a/README.md b/README.md index 452770b76..3df0d9e50 100644 --- a/README.md +++ b/README.md @@ -83,8 +83,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]). diff --git a/src/Compat.jl b/src/Compat.jl index 8a7e68ada..d812a305a 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -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") @@ -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 diff --git a/test/old.jl b/test/old.jl index a08f10505..b1683825f 100644 --- a/test/old.jl +++ b/test/old.jl @@ -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) @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index 95d36b7f2..4cad8895b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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