From b9913973f84b80e9125e37a0312a44bb38239b10 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Thu, 10 Aug 2023 13:28:14 +0400 Subject: [PATCH] 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. --- base/multidimensional.jl | 2 +- test/abstractarray.jl | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/base/multidimensional.jl b/base/multidimensional.jl index f793df068ec5a..314db226b63b7 100644 --- a/base/multidimensional.jl +++ b/base/multidimensional.jl @@ -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) diff --git a/test/abstractarray.jl b/test/abstractarray.jl index 47a81bbbf5b66..29bc514bb1802 100644 --- a/test/abstractarray.jl +++ b/test/abstractarray.jl @@ -1854,3 +1854,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