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

do not catch everything in isassigned #18075

Merged
merged 1 commit into from
Aug 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,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)
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why BoundsError?

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, i didn't realize that worked:

julia> isassigned([], 2)
false

lgtm

Copy link
Sponsor Member Author

@KristofferC KristofferC Aug 17, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But yeah, why not just use checkbounds for the bounds check part?

However, there doesn't seem to be anyway of checking if the field is undef without just trying to access it since that error is thrown from the runtime?

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