Skip to content

Commit b991397

Browse files
authored
Disallow non-index Integer types in isassigned (#50594)
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.
1 parent d1759bc commit b991397

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

base/multidimensional.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1564,7 +1564,7 @@ end
15641564

15651565
isassigned(a::AbstractArray, i::CartesianIndex) = isassigned(a, Tuple(i)...)
15661566
function isassigned(A::AbstractArray, i::Union{Integer, CartesianIndex}...)
1567-
isa(i, Tuple{Vararg{Int}}) || return isassigned(A, CartesianIndex(i...))
1567+
isa(i, Tuple{Vararg{Int}}) || return isassigned(A, CartesianIndex(to_indices(A, i)))
15681568
@boundscheck checkbounds(Bool, A, i...) || return false
15691569
S = IndexStyle(A)
15701570
ninds = length(i)

test/abstractarray.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1854,3 +1854,9 @@ end
18541854
# type stable [x;;] (https://github.com/JuliaLang/julia/issues/45952)
18551855
f45952(x) = [x;;]
18561856
@inferred f45952(1.0)
1857+
1858+
@testset "isassigned with a Bool index" begin
1859+
A = zeros(2,2)
1860+
@test_throws "invalid index: true of type Bool" isassigned(A, 1, true)
1861+
@test_throws "invalid index: true of type Bool" isassigned(A, true)
1862+
end

0 commit comments

Comments
 (0)