diff --git a/base/multidimensional.jl b/base/multidimensional.jl index 32d66c4c54cda..9acb97a486fbb 100644 --- a/base/multidimensional.jl +++ b/base/multidimensional.jl @@ -278,6 +278,7 @@ module IteratorsMD CartesianIndices(A::AbstractArray) = CartesianIndices(axes(A)) + _convert2ind(sz::Bool) = Base.OneTo(Int(sz)) _convert2ind(sz::Integer) = Base.OneTo(sz) _convert2ind(sz::AbstractUnitRange) = first(sz):last(sz) _convert2ind(sz::OrdinalRange) = first(sz):step(sz):last(sz) diff --git a/test/cartesian.jl b/test/cartesian.jl index af0bc466e3d04..8d2651b6f425f 100644 --- a/test/cartesian.jl +++ b/test/cartesian.jl @@ -409,3 +409,10 @@ end # issue #39705 f39705() = Base.Cartesian.@nany 0 _ -> true @test f39705() === false + +@testset "CartesianIndices with Bool" begin + @test @inferred(CartesianIndices((true,))) == CartesianIndices((1,)) + @test @inferred(CartesianIndices((false,))) == CartesianIndices((0,)) + @test @inferred(CartesianIndices((true, false))) == CartesianIndices((1, 0)) + @test @inferred(CartesianIndices((false, true))) == CartesianIndices((0, 1)) +end