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

deleteat! should always throw BoundsError if try to delete past the end #22055

Closed
oxinabox opened this issue May 25, 2017 · 1 comment
Closed
Labels
collections Data structures holding multiple items, e.g. sets error handling Handling of exceptions by Julia or the user

Comments

@oxinabox
Copy link
Contributor

Sometimes,
rather than throwing a BoundsError (which it does most of the time),
deleteat! will throw an InexactError.

julia> x=[1,2,3,5,7]
5-element Array{Int64,1}:
 1
 2
 3
 5
 7

julia> deleteat!(x, 10) # Perfect
ERROR: BoundsError: attempt to access 5-element Array{Int64,1} at index [10]
 in deleteat!(::Array{Int64,1}, ::Int64) at ./array.jl:577

julia> deleteat!(x, [1,10]) # under annotated with info, but still correct type
ERROR: BoundsError
 in deleteat!(::Array{Int64,1}, ::Array{Int64,1}) at ./array.jl:616

julia> deleteat!(x, [10,1]) # sensible
ERROR: ArgumentError: indices must be unique and sorted
 in deleteat!(::Array{Int64,1}, ::Array{Int64,1}) at ./array.jl:614

julia> deleteat!(x, [9,10]) # under annotated with info, but still correct type
ERROR: BoundsError
 in deleteat!(::Array{Int64,1}, ::Array{Int64,1}) at ./array.jl:616

julia> deleteat!(x, [10]) # Problem
ERROR: InexactError()
 in deleteat!(::Array{Int64,1}, ::Array{Int64,1}) at ./array.jl:629

This occurs because it gets to the the ccall and tries to convert a negative value to a UInt
in:

ccall(:jl_array_del_end, Void, (Any, UInt), a, n-p+1)

julia> versioninfo()
Julia Version 0.5.1
Commit 6445c82 (2017-03-05 13:25 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: AMD Opteron 63xx class CPU
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Piledriver)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.7.1 (ORCJIT, bdver2)

looking at the blame suggests the code has not changed since long before 0.5.1 was cut,
so I expect issue to still be present in master

@StefanKarpinski StefanKarpinski changed the title deleteat! should always throw BoundsError if try to delete passed the end deleteat! should always throw BoundsError if try to delete past the end May 25, 2017
@kshyatt kshyatt added collections Data structures holding multiple items, e.g. sets error handling Handling of exceptions by Julia or the user labels May 25, 2017
@laborg
Copy link
Contributor

laborg commented Feb 3, 2022

This has been fixed in #36231

julia> deleteat!(x, [10])
ERROR: BoundsError: attempt to access 5-element Vector{Int64} at index [10]
Stacktrace:
 [1] throw_boundserror(A::Vector{Int64}, I::Tuple{Int64})
   @ Base ./abstractarray.jl:651
 [2] checkbounds
   @ ./abstractarray.jl:616 [inlined]
 [3] _deleteat!(a::Vector{Int64}, inds::Vector{Int64}, dltd::Base.Nowhere)
   @ Base ./array.jl:1387
 [4] _deleteat!
   @ ./array.jl:1383 [inlined]
 [5] deleteat!(a::Vector{Int64}, inds::Vector{Int64})
   @ Base ./array.jl:1377
 [6] top-level scope
   @ REPL[7]:1

@laborg laborg closed this as completed Feb 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
collections Data structures holding multiple items, e.g. sets error handling Handling of exceptions by Julia or the user
Projects
None yet
Development

No branches or pull requests

3 participants