Skip to content

Commit

Permalink
Change isnull argument to Nullable() constructor to hasvalue
Browse files Browse the repository at this point in the history
This method is not currently documented, and the new form is more consistent
with the new structure of the type.
  • Loading branch information
nalimilan committed Sep 15, 2016
1 parent 8da3c10 commit 672c01c
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion base/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,5 @@ immutable Nullable{T}
value::T

Nullable() = new(false)
Nullable(value::T, isnull::Bool=false) = new(!isnull, value)
Nullable(value::T, hasvalue::Bool=true) = new(hasvalue, value)
end
2 changes: 1 addition & 1 deletion base/nullable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
immutable NullException <: Exception
end

Nullable{T}(value::T, isnull::Bool=false) = Nullable{T}(value, isnull)
Nullable{T}(value::T, hasvalue::Bool=true) = Nullable{T}(value, hasvalue)
Nullable() = Nullable{Union{}}()

eltype{T}(::Type{Nullable{T}}) = T
Expand Down
2 changes: 1 addition & 1 deletion test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3118,7 +3118,7 @@ f11858(Any[Type{Foo11858}, Type{Bar11858}, typeof(g11858)])
foo11904(x::Int) = x
@inline function foo11904{S}(x::Nullable{S})
if isbits(S)
Nullable(foo11904(x.value), isnull(x))
Nullable(foo11904(x.value), x.hasvalue)
else
throw_error()
end
Expand Down
6 changes: 3 additions & 3 deletions test/nullable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ for T in types
@test eltype(x) === T
end

# Nullable{T}(value::T, isnull::Bool) = new(isnull, value)
# Nullable{T}(value::T, hasvalue::Bool) = new(hasvalue, value)
for T in types
x = Nullable{T}(zero(T),false)
x = Nullable{T}(zero(T), true)
@test x.hasvalue === true
@test isa(x.value, T)
@test x.value === zero(T)
@test eltype(x) === T

x = Nullable{T}(zero(T),true)
x = Nullable{T}(zero(T), false)
@test x.hasvalue === false
@test isa(x.value, T)
@test eltype(Nullable{T}) === T
Expand Down

0 comments on commit 672c01c

Please sign in to comment.