Skip to content

Commit

Permalink
do not catch everything in isassigned
Browse files Browse the repository at this point in the history
(cherry picked from commit bc0348e)
ref #18075
  • Loading branch information
KristofferC authored and tkelman committed Aug 21, 2016
1 parent 9e1dbfd commit 2082241
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
9 changes: 6 additions & 3 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,15 @@ function _strides{M,T,N}(out::NTuple{M}, A::AbstractArray{T,N})
end

function isassigned(a::AbstractArray, i::Int...)
# TODO
try
a[i...]
true
catch
false
catch e
if isa(e, BoundsError) || isa(e, UndefRefError)
return false
else
rethrow(e)
end
end
end

Expand Down
7 changes: 7 additions & 0 deletions test/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,13 @@ function test_primitives{T}(::Type{T}, shape, ::Type{TestAbstractArray})
@test convert(Array, X) == X
end

let
type TestThrowNoGetindex{T} <: AbstractVector{T} end
Base.length(::TestThrowNoGetindex) = 2
Base.size(::TestThrowNoGetindex) = (2,)
@test_throws ErrorException isassigned(TestThrowNoGetindex{Float64}(), 1)
end

function test_in_bounds(::Type{TestAbstractArray})
n = rand(2:5)
sz = rand(2:5, n)
Expand Down

0 comments on commit 2082241

Please sign in to comment.