Skip to content

Commit

Permalink
Disallow non-index Integer types in isassigned (#50594)
Browse files Browse the repository at this point in the history
Extend #50587 to more general `AbstractArray`s. This is mainly to
disallow `Bool` as an index in `isassigned`, as this isn't supported by
`getindex`. After this
```julia
julia> isassigned(rand(2,2), 1, true)
ERROR: ArgumentError: invalid index: true of type Bool
```
which matches the behavior on v1.9.

(cherry picked from commit b991397)
  • Loading branch information
jishnub authored and IanButterworth committed Aug 19, 2023
1 parent 6867fa6 commit 843937b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/multidimensional.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1564,7 +1564,7 @@ end

isassigned(a::AbstractArray, i::CartesianIndex) = isassigned(a, Tuple(i)...)
function isassigned(A::AbstractArray, i::Union{Integer, CartesianIndex}...)
isa(i, Tuple{Vararg{Int}}) || return isassigned(A, CartesianIndex(i...))
isa(i, Tuple{Vararg{Int}}) || return isassigned(A, CartesianIndex(to_indices(A, i)))
@boundscheck checkbounds(Bool, A, i...) || return false
S = IndexStyle(A)
ninds = length(i)
Expand Down
6 changes: 6 additions & 0 deletions test/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1844,3 +1844,9 @@ end
# type stable [x;;] (https://github.com/JuliaLang/julia/issues/45952)
f45952(x) = [x;;]
@inferred f45952(1.0)

@testset "isassigned with a Bool index" begin
A = zeros(2,2)
@test_throws "invalid index: true of type Bool" isassigned(A, 1, true)
@test_throws "invalid index: true of type Bool" isassigned(A, true)
end

0 comments on commit 843937b

Please sign in to comment.