diff --git a/Project.toml b/Project.toml index 9cf6fcd0..d8049eef 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "StructArrays" uuid = "09ab397b-f2b6-538f-b94a-2f83cf4a842a" -version = "0.6.12" +version = "0.6.13" [deps] Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" diff --git a/src/collect.jl b/src/collect.jl index 5cd9f003..b5e9e710 100644 --- a/src/collect.jl +++ b/src/collect.jl @@ -122,9 +122,9 @@ _widenstructarray(dest::AbstractArray, i, ::Type{T}) where {T} = _widenarray(des _widenarray(dest::AbstractArray{T}, i, ::Type{T}) where {T} = dest function _widenarray(dest::AbstractArray, i, ::Type{T}) where T - new = similar(dest, T, length(dest)) + new = similar(dest, T) copyto!(new, firstindex(new), dest, firstindex(dest), i-1) - new + return new end """ diff --git a/test/runtests.jl b/test/runtests.jl index 53035fd7..7766604a 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -814,11 +814,19 @@ pair_structarray((first, last)) = StructArray{Pair{eltype(first), eltype(last)}} end @testset "collect2D" begin - s = (l for l in [(a=i, b=j) for i in 1:3, j in 1:4]) + s = ((a=i, b=j) for i in 1:3, j in 1:4) v = collect_structarray(s) @test size(v) == (3, 4) + @test eltype(v) == @NamedTuple{a::Int, b::Int} @test v.a == [i for i in 1:3, j in 1:4] @test v.b == [j for i in 1:3, j in 1:4] + + s = (i == 1 ? (a=nothing, b=j) : (a=i, b=j) for i in 1:3, j in 1:4) + v = collect_structarray(s) + @test size(v) == (3, 4) + @test eltype(v) == @NamedTuple{a::Union{Int, Nothing}, b::Int} + @test v.a == [i == 1 ? nothing : i for i in 1:3, j in 1:4] + @test v.b == [j for i in 1:3, j in 1:4] end @testset "collectoffset" begin