diff --git a/base/array.jl b/base/array.jl index d62436ca30497..33024aef07a89 100644 --- a/base/array.jl +++ b/base/array.jl @@ -954,7 +954,7 @@ end getindex(a::Array, r::AbstractUnitRange{Bool}) = getindex(a, to_index(r)) function getindex(A::Array, c::Colon) - lI = length(A) + lI = length(A)::Int X = similar(A, lI) if lI > 0 unsafe_copyto!(X, 1, A, 1, lI) diff --git a/test/arrayops.jl b/test/arrayops.jl index f9c592e672973..e1588263e3f55 100644 --- a/test/arrayops.jl +++ b/test/arrayops.jl @@ -221,6 +221,12 @@ end end end +@testset "return type inference of `getindex(::Array, ::Colon)`" begin + f = a -> a[:] + @test Vector === Base.infer_return_type(f, Tuple{Array}) + @test Vector{Float32} === Base.infer_return_type(f, Tuple{Array{Float32}}) +end + struct Z26163 <: AbstractArray{Int,0}; end Base.size(::Z26163) = () Base.getindex(::Z26163) = 0