Skip to content

Commit 9ffecc0

Browse files
committed
Add Nothing and Cvoid
1 parent 3832a22 commit 9ffecc0

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
@@ -259,6 +259,8 @@ Currently, the `@compat` macro supports the following syntaxes:
259259

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

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

264266
* `@__DIR__` has been added ([#18380])
@@ -414,3 +416,4 @@ includes this fix. Find the minimum version from there.
414416
[#25021]: https://github.com/JuliaLang/julia/issues/25021
415417
[#25056]: https://github.com/JuliaLang/julia/issues/25056
416418
[#25057]: https://github.com/JuliaLang/julia/issues/25057
419+
[#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
@@ -994,6 +994,13 @@ end
994994
export axes
995995
end
996996

997+
# 0.7.0-DEV.3137
998+
@static if !isdefined(Base, :Nothing)
999+
const Nothing = Void
1000+
const Cvoid = Void
1001+
export Nothing, Cvoid
1002+
end
1003+
9971004
@static if !isdefined(Base, :Some)
9981005
import Base: promote_rule, convert
9991006
if VERSION >= v"0.6.0"
@@ -1002,35 +1009,35 @@ end
10021009
value::T
10031010
end
10041011
promote_rule(::Type{Some{S}}, ::Type{Some{T}}) where {S,T} = Some{promote_type(S, T)}
1005-
promote_rule(::Type{Some{T}}, ::Type{Void}) where {T} = Union{Some{T}, Void}
1012+
promote_rule(::Type{Some{T}}, ::Type{Nothing}) where {T} = Union{Some{T}, Nothing}
10061013
convert(::Type{Some{T}}, x::Some) where {T} = Some{T}(convert(T, x.value))
1007-
convert(::Type{Union{Some{T}, Void}}, x::Some) where {T} = convert(Some{T}, x)
1008-
convert(::Type{Union{T, Void}}, x::Any) where {T} = convert(T, x)
1014+
convert(::Type{Union{Some{T}, Nothing}}, x::Some) where {T} = convert(Some{T}, x)
1015+
convert(::Type{Union{T, Nothing}}, x::Any) where {T} = convert(T, x)
10091016
""")
10101017
else
10111018
include_string(@__MODULE__, """
10121019
immutable Some{T}
10131020
value::T
10141021
end
10151022
promote_rule{S,T}(::Type{Some{S}}, ::Type{Some{T}}) = Some{promote_type(S, T)}
1016-
promote_rule{T}(::Type{Some{T}}, ::Type{Void}) = Union{Some{T}, Void}
1023+
promote_rule{T}(::Type{Some{T}}, ::Type{Nothing}) = Union{Some{T}, Nothing}
10171024
convert{T}(::Type{Some{T}}, x::Some) = Some{T}(convert(T, x.value))
1018-
convert{T}(::Type{Union{Some{T}, Void}}, x::Some) = convert(Some{T}, x)
1019-
convert{T}(::Type{Union{T, Void}}, x::Any) = convert(T, x)
1025+
convert{T}(::Type{Union{Some{T}, Nothing}}, x::Some) = convert(Some{T}, x)
1026+
convert{T}(::Type{Union{T, Nothing}}, x::Any) = convert(T, x)
10201027
""")
10211028
end
1022-
convert(::Type{Void}, x::Any) = throw(MethodError(convert, (Void, x)))
1023-
convert(::Type{Void}, x::Void) = nothing
1029+
convert(::Type{Nothing}, x::Any) = throw(MethodError(convert, (Nothing, x)))
1030+
convert(::Type{Nothing}, x::Nothing) = nothing
10241031
coalesce(x::Any) = x
10251032
coalesce(x::Some) = x.value
1026-
coalesce(x::Void) = nothing
1033+
coalesce(x::Nothing) = nothing
10271034
#coalesce(x::Missing) = missing
10281035
coalesce(x::Any, y...) = x
10291036
coalesce(x::Some, y...) = x.value
1030-
coalesce(x::Void, y...) = coalesce(y...)
1031-
#coalesce(x::Union{Void, Missing}, y...) = coalesce(y...)
1037+
coalesce(x::Nothing, y...) = coalesce(y...)
1038+
#coalesce(x::Union{Nothing, Missing}, y...) = coalesce(y...)
10321039
notnothing(x::Any) = x
1033-
notnothing(::Void) = throw(ArgumentError("nothing passed to notnothing"))
1040+
notnothing(::Nothing) = throw(ArgumentError("nothing passed to notnothing"))
10341041
export Some, coalesce
10351042
else
10361043
import Base: notnothing

test/runtests.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,10 @@ end
10351035
@test axes(1) == ()
10361036
@test axes(1,1) == 1:1
10371037

1038+
# 0.7.0-DEV.3137
1039+
@test Nothing === (isdefined(Base, :Nothing) ? Base.Nothing : Base.Void)
1040+
@test Nothing === Cvoid
1041+
10381042
# 0.7.0-DEV.3017
10391043
@test isa(Some(1), Some{Int})
10401044
@test convert(Some{Float64}, Some(1)) == Some(1.0)

0 commit comments

Comments
 (0)