Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

constructor update #1

Open
JeffBezanson opened this issue Dec 19, 2017 · 0 comments
Open

constructor update #1

JeffBezanson opened this issue Dec 19, 2017 · 0 comments

Comments

@JeffBezanson
Copy link
Contributor

JeffBezanson commented Dec 19, 2017

When JuliaLang/julia#23273 is merged, these changes will be needed:

diff --git a/base/nullable.jl b/base/nullable.jl
index bb30755..3d08709 100644
--- a/base/nullable.jl
+++ b/base/nullable.jl
@@ -51,21 +51,11 @@ Nullable() = Nullable{Union{}}()
 
 eltype(::Type{Nullable{T}}) where {T} = T
 
-convert(::Type{Nullable{T}}, x::Nullable{T}) where {T} = x
-convert(::Type{Nullable   }, x::Nullable   ) = x
+convert(::Type{T}, x::T) where {T<:Nullable} = x
+convert(::Type{Nullable}, x::Nullable) = x
 
-convert(t::Type{Nullable{T}}, x::Any) where {T} = convert(t, convert(T, x))
-
-function convert(::Type{Nullable{T}}, x::Nullable) where T
-    return isnull(x) ? Nullable{T}() : Nullable{T}(convert(T, get(x)))
-end
-
-convert(::Type{Nullable{T}}, x::T) where {T<:Nullable} = Nullable{T}(x)
-convert(::Type{Nullable{T}}, x::T) where {T} = Nullable{T}(x)
-convert(::Type{Nullable   }, x::T) where {T} = Nullable{T}(x)
-
-convert(::Type{Nullable{T}}, ::Void) where {T} = Nullable{T}()
-convert(::Type{Nullable   }, ::Void) = Nullable{Union{}}()
+convert(::Type{T}, x::Any ) where {T<:Nullable} = T(x)
+convert(::Type{T}, x::Void) where {T<:Nullable} = T()
 
 promote_rule(::Type{Nullable{S}}, ::Type{T}) where {S,T} = Nullable{promote_type(S, T)}
 promote_rule(::Type{Nullable{S}}, ::Type{Nullable{T}}) where {S,T} = Nullable{promote_type(S, T)}
diff --git a/base/nullabletype.jl b/base/nullabletype.jl
index 8c1c9c3..c09b2a0 100644
--- a/base/nullabletype.jl
+++ b/base/nullabletype.jl
@@ -5,5 +5,8 @@ struct Nullable{T}
     value::T
 
     Nullable{T}() where {T} = new(false)
-    Nullable{T}(value::T, hasvalue::Bool=true) where {T} = new(hasvalue, value)
+    Nullable{T}(value, hasvalue::Bool=true) where {T} = new(hasvalue, value)
+    Nullable{T}(::Void) where {T} = Nullable{T}()
+    (::Type{Nullable{Void}})(::Void) = new{Void}(true, nothing)
+    Nullable{T}(x::Nullable) where {T} = isnull(x) ? Nullable{T}() : Nullable{T}(convert(T, get(x)))
 end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant