-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
checkbounds doesn't obey API for strings #24840
Comments
julia> A = rand(2,2)
2×2 Array{Float64,2}:
0.106665 0.653657
0.0492862 0.985517
julia> checkbounds(Bool, A, 1, 1)
true
julia> checkbounds(Bool, A, 1, 3)
false
julia> checkbounds(A, 1, 1)
julia> checkbounds(A, 1, 3)
ERROR: BoundsError: attempt to access 2×2 Array{Float64,2} at index [1, 3]
Stacktrace:
[1] throw_boundserror(::Array{Float64,2}, ::Tuple{Int64,Int64}) at ./abstractarray.jl:434
[2] checkbounds(::Array{Float64,2}, ::Int64, ::Int64) at ./abstractarray.jl:399
[3] top-level scope OK to close? |
The |
It's still a mess for strings: julia> checkbounds("foo", 1)
true
julia> checkbounds("foo", 0)
ERROR: BoundsError: attempt to access "foo"
at index [0]
Stacktrace:
[1] checkbounds(::String, ::Int64) at ./strings/basic.jl:391
[2] top-level scope
julia> checkbounds(Bool, "foo", 0)
ERROR: MethodError: no method matching checkbounds(::Type{Bool}, ::String, ::Int64)
Closest candidates are:
checkbounds(::Type{Bool}, ::AbstractArray, ::Any) at abstractarray.jl:383
checkbounds(::Type{Bool}, ::AbstractArray, ::Any...) at abstractarray.jl:378
checkbounds(::AbstractArray, ::Any...) at abstractarray.jl:398
... |
Seems straightforward enough to fix. If we bring strings in line with other types here do we think it will break anything? |
Probably not? Hard to say without trying it. |
Cc: @bkamins |
The documentation for
checkbounds
says that it returns true if an index (or indices) are in bounds:However, the methods seem to variously return
nothing
or throw an error, returntrue
or throw an error and maybe somewhere there's a method that actually does what the docs say.The text was updated successfully, but these errors were encountered: