Skip to content

Commit e2fe9a2

Browse files
authored
Avoid piracy in cat (#254)
* Avoid piracy in cat * Add test
1 parent 1afecf4 commit e2fe9a2

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/structarray.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,10 +445,11 @@ end
445445

446446
for op in [:cat, :hcat, :vcat]
447447
@eval begin
448-
function Base.$op(args::StructArray...; kwargs...)
448+
function Base.$op(arg1::StructArray, argsrest::StructArray...; kwargs...)
449+
args = (arg1, argsrest...)
449450
f = key -> $op((getproperty(t, key) for t in args)...; kwargs...)
450451
T = mapreduce(eltype, promote_type, args)
451-
StructArray{T}(map(f, propertynames(args[1])))
452+
StructArray{T}(map(f, propertynames(arg1)))
452453
end
453454
end
454455
end

test/runtests.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,10 @@ end
586586
horizontal_concat = StructArray{Pair{Int, String}}(([3 1; 5 6], ["a" "a"; "b" "b"]))
587587
@test cat(t, t2; dims=2)::StructArray == horizontal_concat == hcat(t, t2)
588588
@test hcat(t, t2) isa StructArray
589+
590+
# check that cat(dims=1) doesn't commit type piracy (#254)
591+
# We only test that this works, the return value is immaterial
592+
@test cat(dims=1) == vcat()
589593
end
590594

591595
f_infer() = StructArray{ComplexF64}((rand(2,2), rand(2,2)))

0 commit comments

Comments
 (0)