Skip to content
This repository was archived by the owner on May 4, 2019. It is now read-only.

Commit 6a90a4a

Browse files
Merge pull request #59 from mbauman/checkbounds
Update index checkbounds API
2 parents 6e48730 + a55ea88 commit 6a90a4a

File tree

2 files changed

+16
-21
lines changed

2 files changed

+16
-21
lines changed

src/indexing.jl

+7-6
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,21 @@ end
6060

6161
# ----- Base._checkbounds ----------------------------------------------------#
6262

63-
function Base._checkbounds{T<:Real}(sz::Int, x::Nullable{T})
64-
isnull(x) ? throw(NullException()) : Base._checkbounds(sz, get(x))
63+
function Base.checkbounds{T<:Real}(::Type{Bool}, sz::Int, x::Nullable{T})
64+
isnull(x) ? throw(NullException()) : checkbounds(Bool, sz, get(x))
6565
end
6666

67-
function Base._checkbounds(sz::Int, I::NullableVector{Bool})
68-
length(I) == sz || throw(BoundsError())
67+
function Base.checkbounds(::Type{Bool}, sz::Int, I::NullableVector{Bool})
68+
anynull(I) && throw(NullException())
69+
length(I) == sz
6970
end
7071

71-
function Base._checkbounds{T<:Real}(sz::Int, I::NullableArray{T})
72+
function Base.checkbounds{T<:Real}(::Type{Bool}, sz::Int, I::NullableArray{T})
7273
inbounds = true
7374
anynull(I) && throw(NullException())
7475
for i in 1:length(I)
7576
@inbounds v = unsafe_getvalue_notnull(I, i)
76-
inbounds &= Base._checkbounds(sz, v)
77+
inbounds &= checkbounds(Bool, sz, v)
7778
end
7879
return inbounds
7980
end

test/indexing.jl

+9-15
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ module TestIndexing
33
using NullableArrays
44
import NullableArrays: unsafe_getindex_notnull,
55
unsafe_getvalue_notnull
6-
import Base: _checkbounds
76

87
x = NullableArray(Int, (5, 2))
98

@@ -170,28 +169,23 @@ module TestIndexing
170169
@test isequal(unsafe_getvalue_notnull(X, 1), 1)
171170
@test isequal(unsafe_getvalue_notnull(X, 2), 2)
172171

173-
#----- test Base._checkbounds -----#
172+
#----- test Base.checkbounds -----#
174173

175174
X = NullableArray([1:10...])
176175
b = vcat(false, fill(true, 9))
177176

178-
# Base._checkbounds{T<:Real}(sz::Int, x::Nullable{T})
179-
@test_throws NullException _checkbounds(1, Nullable(1, true))
180-
@test _checkbounds(10, Nullable(1)) == true
177+
# Base.checkbounds{T<:Real}(::Type{Bool}, sz::Int, x::Nullable{T})
178+
@test_throws NullException checkbounds(Bool, 1, Nullable(1, true))
179+
@test checkbounds(Bool, 10, Nullable(1)) == true
181180
@test isequal(X[Nullable(1)], Nullable(1))
182181

183-
# Base._checkbounds(sz::Int, X::NullableVector{Bool})
184-
@test _checkbounds(5, NullableArray([true, false, true, false, true]))
185-
@test_throws(BoundsError,
186-
_checkbounds(5,
187-
NullableArray([true, false, true, true])
188-
)
189-
)
182+
# Base.checkbounds(::Type{Bool}, sz::Int, X::NullableVector{Bool})
183+
@test checkbounds(Bool, 5, NullableArray([true, false, true, false, true]))
190184
@test isequal(X[b], NullableArray([2:10...]))
191185

192-
# Base._checkbounds{T<:Real}(sz::Int, I::NullableArray{T})
193-
@test _checkbounds(10, NullableArray([1:10...]))
194-
@test _checkbounds(10, NullableArray([10, 11])) == false
186+
# Base.checkbounds{T<:Real}(::Type{Bool}, sz::Int, I::NullableArray{T})
187+
@test checkbounds(Bool, 10, NullableArray([1:10...]))
188+
@test checkbounds(Bool, 10, NullableArray([10, 11])) == false
195189
@test_throws BoundsError checkbounds(X, NullableArray([10, 11]))
196190

197191
#---- test Base.to_index -----#

0 commit comments

Comments
 (0)