diff --git a/src/FixedSizeArray.jl b/src/FixedSizeArray.jl index 9b5f917..26f63df 100644 --- a/src/FixedSizeArray.jl +++ b/src/FixedSizeArray.jl @@ -354,7 +354,12 @@ end # `getindex` with a `Colon` for the index: better effects than with the generic fallback function Base.getindex(a::FixedSizeArray, ::Colon) - copy(a) + c = copy(a) + if a isa AbstractVector + c + else + reshape(c, :) + end end # `copyto!` diff --git a/test/runtests.jl b/test/runtests.jl index 8aba697..18ed3b3 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -460,7 +460,7 @@ end m = FixedSizeArray(rand(2, 2))::FixedSizeArray @test m == copy(m) @test m !== copy(m) - @test m == m[:] + @test reshape(m, :) == m[:] @test m !== m[:] end @@ -708,4 +708,13 @@ end tuple(m...) end[] == NTuple{3, Int} end + + @testset "getindex with a single colon must return an `AbstractVector`" begin + for m in 0:3 + @test let a = FixedSizeArray{Float32}(undef, ntuple(Returns(1), m)) + a::AbstractArray{<:Any, m} + a[:] isa AbstractVector + end + end + end end