diff --git a/src/vector_of_array.jl b/src/vector_of_array.jl index 95777e05..092215e4 100644 --- a/src/vector_of_array.jl +++ b/src/vector_of_array.jl @@ -1162,6 +1162,12 @@ end ) where {T} return similar(Array{T}, dims) end +# Disambiguates against Base's integer-dimension similar fallback on Julia ≤ 1.11. +@inline function Base.similar( + VA::AbstractVectorOfArray, ::Type{T}, dims::Tuple{Integer, Vararg{Integer}} + ) where {T} + return similar(Array{T}, dims) +end # fill! diff --git a/test/Core/similar_tests.jl b/test/Core/similar_tests.jl new file mode 100644 index 00000000..2c01dd07 --- /dev/null +++ b/test/Core/similar_tests.jl @@ -0,0 +1,22 @@ +using RecursiveArrayTools, Test + +@testset "similar with explicit dimensions" begin + data = [[1, 2], [3, 4]] + for A in (VectorOfArray(data), DiffEqArray(data, [0, 1])) + @testset "$(nameof(typeof(A))) $dims" for (dims, expected_size) in ( + ((Int32(2), Int32(3)), (2, 3)), + ((UInt8(2), UInt8(3)), (2, 3)), + ((big(2), big(3)), (2, 3)), + ((true, false), (1, 0)), + ((2, 3), (2, 3)), + ((), ()), + ((Base.OneTo(2), Base.OneTo(3)), (2, 3)), + ((2, Base.OneTo(3)), (2, 3)), + ) + result = similar(A, Float64, dims) + @test result isa Array + @test size(result) == expected_size + @test eltype(result) === Float64 + end + end +end diff --git a/test/runtests.jl b/test/runtests.jl index b50e7b45..d9b8c39a 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -19,6 +19,7 @@ run_tests(; @time @safetestset "Partitions and StaticArrays Tests" include("Core/partitions_and_static_arrays.jl") @time @safetestset "VecOfArr Indexing Tests" include("Core/basic_indexing.jl") @time @safetestset "VecOfArr Interface Tests" include("Core/interface_tests.jl") + @time @safetestset "VecOfArr Similar Tests" include("Core/similar_tests.jl") @time @safetestset "Public API Tests" include("Core/public_api_test.jl") @time @safetestset "Table traits" include("Core/tabletraits.jl") @time @safetestset "StaticArrays Tests" include("Core/copy_static_array_test.jl")