Skip to content

Commit 2655456

Browse files
committed
Add Nothing and Cvoid
1 parent 0e64ae1 commit 2655456

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,8 @@ Currently, the `@compat` macro supports the following syntaxes:
258258

259259
* `indices` is now `axes` ([#25057]).
260260

261+
* `Void` is now `Nothing` with an alias `Cvoid` for C interop ([#25162]).
262+
261263
## New macros
262264

263265
* `@__DIR__` has been added ([#18380])
@@ -413,3 +415,4 @@ includes this fix. Find the minimum version from there.
413415
[#25012]: https://github.com/JuliaLang/julia/issues/25012
414416
[#25056]: https://github.com/JuliaLang/julia/issues/25056
415417
[#25057]: https://github.com/JuliaLang/julia/issues/25057
418+
[#25162]: https://github.com/JuliaLang/julia/issues/25162

src/Compat.jl

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,13 @@ end
960960
export axes
961961
end
962962

963+
# 0.7.0-DEV.3137
964+
@static if !isdefined(Base, :Nothing)
965+
const Nothing = Void
966+
const Cvoid = Void
967+
export Nothing, Cvoid
968+
end
969+
963970
@static if !isdefined(Base, :Some)
964971
import Base: promote_rule, convert
965972
if VERSION >= v"0.6.0"
@@ -968,35 +975,35 @@ end
968975
value::T
969976
end
970977
promote_rule(::Type{Some{S}}, ::Type{Some{T}}) where {S,T} = Some{promote_type(S, T)}
971-
promote_rule(::Type{Some{T}}, ::Type{Void}) where {T} = Union{Some{T}, Void}
978+
promote_rule(::Type{Some{T}}, ::Type{Nothing}) where {T} = Union{Some{T}, Nothing}
972979
convert(::Type{Some{T}}, x::Some) where {T} = Some{T}(convert(T, x.value))
973-
convert(::Type{Union{Some{T}, Void}}, x::Some) where {T} = convert(Some{T}, x)
974-
convert(::Type{Union{T, Void}}, x::Any) where {T} = convert(T, x)
980+
convert(::Type{Union{Some{T}, Nothing}}, x::Some) where {T} = convert(Some{T}, x)
981+
convert(::Type{Union{T, Nothing}}, x::Any) where {T} = convert(T, x)
975982
""")
976983
else
977984
include_string(@__MODULE__, """
978985
immutable Some{T}
979986
value::T
980987
end
981988
promote_rule{S,T}(::Type{Some{S}}, ::Type{Some{T}}) = Some{promote_type(S, T)}
982-
promote_rule{T}(::Type{Some{T}}, ::Type{Void}) = Union{Some{T}, Void}
989+
promote_rule{T}(::Type{Some{T}}, ::Type{Nothing}) = Union{Some{T}, Nothing}
983990
convert{T}(::Type{Some{T}}, x::Some) = Some{T}(convert(T, x.value))
984-
convert{T}(::Type{Union{Some{T}, Void}}, x::Some) = convert(Some{T}, x)
985-
convert{T}(::Type{Union{T, Void}}, x::Any) = convert(T, x)
991+
convert{T}(::Type{Union{Some{T}, Nothing}}, x::Some) = convert(Some{T}, x)
992+
convert{T}(::Type{Union{T, Nothing}}, x::Any) = convert(T, x)
986993
""")
987994
end
988-
convert(::Type{Void}, x::Any) = throw(MethodError(convert, (Void, x)))
989-
convert(::Type{Void}, x::Void) = nothing
995+
convert(::Type{Nothing}, x::Any) = throw(MethodError(convert, (Nothing, x)))
996+
convert(::Type{Nothing}, x::Nothing) = nothing
990997
coalesce(x::Any) = x
991998
coalesce(x::Some) = x.value
992-
coalesce(x::Void) = nothing
999+
coalesce(x::Nothing) = nothing
9931000
#coalesce(x::Missing) = missing
9941001
coalesce(x::Any, y...) = x
9951002
coalesce(x::Some, y...) = x.value
996-
coalesce(x::Void, y...) = coalesce(y...)
997-
#coalesce(x::Union{Void, Missing}, y...) = coalesce(y...)
1003+
coalesce(x::Nothing, y...) = coalesce(y...)
1004+
#coalesce(x::Union{Nothing, Missing}, y...) = coalesce(y...)
9981005
notnothing(x::Any) = x
999-
notnothing(::Void) = throw(ArgumentError("nothing passed to notnothing"))
1006+
notnothing(::Nothing) = throw(ArgumentError("nothing passed to notnothing"))
10001007
export Some, coalesce
10011008
else
10021009
import Base: notnothing

test/runtests.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,10 @@ end
10231023
@test axes(1) == ()
10241024
@test axes(1,1) == 1:1
10251025

1026+
# 0.7.0-DEV.3137
1027+
@test Nothing === (isdefined(Base, :Nothing) ? Base.Nothing : Base.Void)
1028+
@test Nothing === Cvoid
1029+
10261030
# 0.7.0-DEV.3017
10271031
@test isa(Some(1), Some{Int})
10281032
@test convert(Some{Float64}, Some(1)) == Some(1.0)

0 commit comments

Comments
 (0)